我一直在尝试将页面的滚动设置为某个div。请让我知道我该怎么做。下面是我的代码,其中li中的每个选项都移动到特定的div。我在doucument.ready函数中尝试了这个$("#header3").click();,但它不起作用。
请帮帮忙!
<ul id="navigation">
<LI><A class="home selected-lice"href="#header">Home</A></LI>
<LI><A href="#header4">Partners</A></LI>
<LI><A class="about" href="#header5">About Us</A></LI>
<LI><A class="contact" href="#header6">Contact Us</A></LI>
</ul><!-- end of #navigation -->发布于 2012-06-17 19:39:41
或者,您可以使用此选项滚动到页面上的特定元素,加载动画
$(function(){
$('html, body').animate({ scrollTop: $("#header1").offset().top });
});发布于 2012-06-17 19:44:27
请查看此链接:http://css-tricks.com/snippets/jquery/smooth-scrolling/
或者尝试用一些滚动来覆盖通常的锚点行为。如下所示:
$(function(){
$('a[href^=#]').click(function(e){
var name = $(this).attr('href').substr(1);
var pos = $('a[name='+name+']').offset();
$('body').animate({ scrollTop: pos.top });
e.preventDefault();
});
});https://stackoverflow.com/questions/11071000
复制相似问题