Last active
October 4, 2018 19:37
-
-
Save DevTarakanova/fda01ecece9277ac84aaf2201077f4cf 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
$(document).ready(function(){ | |
$("#menu").on("click","a", function (event) { | |
event.preventDefault(); //отменяем стандартную обработку нажатия по ссылке | |
var id = $(this).attr('href'), //забираем идентификатор бока с атрибута href | |
top = $(id).offset().top; //узнаем высоту от начала страницы до блока на который ссылается якорь | |
$('body,html').animate({scrollTop: top}, 1500); //анимируем переход на расстояние - top за 1500 мс | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment