开发者

Having trouble getting Ariel Flesler's ScrollTo working

开发者 https://www.devze.com 2023-01-20 20:52 出处:网络
I\'ve been trying to implement Ariel Fl开发者_如何学Cesler\'s ScrollTo plugin, but I can seem to figure out how to initiate it. This is his website:

I've been trying to implement Ariel Fl开发者_如何学Cesler's ScrollTo plugin, but I can seem to figure out how to initiate it. This is his website:

http://flesler.blogspot.com/

What I would like to do is have a static navigation, and when the user clicks a nav link, the content scrolls within a particular div. I have a pretty good understanding of jQuery, and it seems like this plugin should be really easy to use, but the documentation kinda sucks for demonstrating how to actually use it.


Peter is right, you can do this:

     $(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;

            }

          }

        });

      });
0

精彩评论

暂无评论...
验证码 换一张
取 消