【问题标题】:Having trouble getting Ariel Flesler's ScrollTo working无法让 Ariel Flesler 的 ScrollTo 正常工作
【发布时间】:2010-10-20 17:35:35
【问题描述】:

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

http://flesler.blogspot.com/

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

【问题讨论】:

  • 听起来使用 jQuery .animate() 比使用整个插件更简单。

标签: jquery plugins navigation scroll scrollto


【解决方案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;

            }

          }

        });

      });

【讨论】:

    猜你喜欢
    • 2012-06-15
    • 1970-01-01
    • 1970-01-01
    • 2011-07-01
    • 2012-09-05
    • 2017-11-06
    • 2011-09-06
    • 1970-01-01
    • 2023-03-10
    相关资源
    最近更新 更多