1

我一直在尝试将页面的滚动设置为某个 div。请让我知道我该怎么做。以下是我的代码,其中 li 中的每个选项都移动到某个 div 。我试过这个 $("#header3").click(); 在 doucument.ready 函数中,但它不起作用。

请帮忙!

<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 -->
4

2 回答 2

3

或者,您可以使用它在页面加载时滚动到带有动画的特定元素:

$(function(){
   $('html, body').animate({ scrollTop: $("#header1").offset().top });
});
于 2012-06-17T11:39:41.343 回答
0

检查此链接: 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();
  });
});
于 2012-06-17T11:44:26.757 回答