Created
December 4, 2016 19:04
-
-
Save trof808/55a28ffa3268254af5880c0129a78014 to your computer and use it in GitHub Desktop.
smooth scroll to element
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(){ | |
$('.go_to').click( function() { // ловим клик по ссылке с классом go_to | |
var scroll_el = $(this).attr('href'); // возьмем содержимое атрибута href, должен быть селектором, т.е. например начинаться с # или . | |
if ($(scroll_el).length != 0) { // проверим существование элемента чтобы избежать ошибки | |
$('html, body').animate({ scrollTop: $(scroll_el).offset().top }, 500); // анимируем скроолинг к элементу scroll_el | |
} | |
return false; // выключаем стандартное действие | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment