1

我一直在尝试实现 Ariel Flesler 的 ScrollTo 插件,但我似乎知道如何启动它。这是他的网站:

http://flesler.blogspot.com/

我想做的是有一个静态导航,当用户单击导航链接时,内容会在特定的 div 内滚动。我对 jQuery 有很好的理解,而且看起来这个插件应该很容易使用,但是文档对于演示如何实际使用它有点糟糕。

4

1 回答 1

1

彼得是对的,你可以这样做:

     $(document).ready(function(){

        $('a[href*=#]').click(function() {

          if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')

          && location.hostname == this.hostname) {

            var $target = $(this.hash);

            $target = $target.length && $target 
            || $('[name=' + this.hash.slice(1) +']');
   if ($target.length) {

              var targetOffset = $target.offset().top;

              $('html,body')

              .animate({scrollTop: targetOffset}, 1000);

             return false;

            }

          }

        });

      });
于 2010-10-20T18:34:38.677 回答