开发者

jquery scrolling, cant get easing to work

开发者 https://www.devze.com 2023-02-22 02:09 出处:网络
I want to make a one page website with a div (navigation) with fixed position and z-index on 999. The goal is to make the div stay on top and all the other content scroll.

I want to make a one page website with a div (navigation) with fixed position and z-index on 999.

The goal is to make the div stay on top and all the other content scroll. I got this working properly, however i want to make it "more smooth" with easing, but everything i try makes the script stop working. This is the working script:

 $(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;  
          }  
        }  
      });  
    });`  

Can anyone help me with the easing part? I want the scrolling to start fast and slowing down 开发者_StackOverflow中文版when it is near the anchor.

thanks in advance.


replace

$('html,body') .animate({scrollTop: targetOffset}, 1000) ;

with

$('html,body') .animate({scrollTop: targetOffset}, 1000, 'easeOutQuart');

Make sure you have included jQuery UI core and jQuery Effects core.

0

精彩评论

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