How to scroll to an element when a link is clicked
This question already has an answer here:
$("li a").click(function(){
$('html, body').animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 1000);
return false;
});
这将适用于李元素中的所有链接。
$(document).scrollTop($('div#content').offset().top)
Here is a script I like to use whenever I want to enable a "scroll to" type of Jquery effect.
http://cferdinandi.github.io/smooth-scroll/
链接地址: http://www.djcxy.com/p/23088.html上一篇: Javascript(最好是Jquery),它会模仿hashtags的行为
下一篇: 如何在单击链接时滚动到元素