Created
February 20, 2015 22:15
-
-
Save freewayspb/277cc7bb0b980e95157e to your computer and use it in GitHub Desktop.
smoothScroll
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(){ | |
// = Добавляем ссылку наверх к заголовку | |
$('h2').append('<a href="#header">top</a>'); | |
// = Вешаем событие прокрутки к нужному месту | |
// на все ссылки якорь которых начинается на # | |
$('a[href^="#"]').bind('click.smoothscroll',function (e) { | |
e.preventDefault(); | |
var target = this.hash, | |
$target = $(target); | |
$('html, body').stop().animate({ | |
'scrollTop': $target.offset().top | |
}, 900, 'swing', function () { | |
window.location.hash = target; | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment