2013-10-24 72 views
3

,我有以下的jQuery代码jQuery的平滑滚动偏移

$(document).ready(function(){ 
    $('a[href^="#"]').on('click',function (e) { 
     e.preventDefault(); 

     var target = this.hash, 
     $target = $(target); 

     $('html, body').stop().animate({ 
      'scrollTop': $target.offset().top 
     }, 900, 'swing', function() { 
      window.location.hash = target; 
     }); 
    }); 
}); 

这是一个滚动的插件,它顺利地向下滚动到页面的内部链接。我想抵消-140px的学校,所以它不会向右滚动到DIV。

这是如何实现的?

回答

8

尝试...

$('html, body').stop().animate({ 
    'scrollTop': $target.offset().top-140 
}, 900, 'swing', function() { 
    window.location.hash = target; 
}); 
+0

这伟大的工作,谢谢! – user2716389