Last active
February 8, 2018 10:55
-
-
Save VasylKyryliuk/42d91761a0bedde0f599ce0773a7616c to your computer and use it in GitHub Desktop.
Перехід по якорю даже при перезагрузці сторінки
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Перехід по якорям | |
$('a[href^="#"]').click(function(){ | |
//Сохраняем значение атрибута href в переменной: | |
var target = $(this).attr('href'); | |
$('html, body').animate({scrollTop: $(target).offset().top}, 800); | |
return false; | |
}); | |
//Перехід по якорям при переході на сторінку | |
if (window.location.hash) { | |
scroll(0, 0); | |
// smooth scroll to the anchor id | |
$('html, body').animate({ | |
scrollTop: $(window.location.hash).offset().top + 'px' | |
}, 1500, 'swing'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment