2011-11-16 69 views
0

我從這個頁面中實現如下代碼:http://tympanus.net/codrops/2010/06/02/smooth-vertical-or-horizontal-page-scrolling-with-jquery/jQuery的滾動

$(document).ready(function() { 

      $('ul.navone li a, ul.navtwo li a,a.toplink, a.bodylink').bind('click',function(event){ 
       var $anchor = $(this); 

       $('html, body, header').stop().animate({ 
        scrollTop: $($anchor.attr('href')).offset().top 
       }, 1500,'easeInOutExpo'); 

       event.preventDefault(); 
      }); 
     }); 

這一切都正常工作。

但是,在我的佈局中,我有一個固定的標題div(即它在用戶滾動時保持原位)。因此,我需要爲117像素的滾動腳本設置偏移量。

請問我該怎麼做?

回答

2

將是類似的東西:

$(document).ready(function() { 

      $('ul.navone li a, ul.navtwo li a,a.toplink, a.bodylink').bind('click',function(event){ 
       var $anchor = $(this); 

       $('html, body, header').stop().animate({ 
        scrollTop: ($($anchor.attr('href')).offset().top + 117) 
       }, 1500,'easeInOutExpo'); 

       event.preventDefault(); 
      }); 
     }); 

只需添加+117至scrollTop的位置

+0

優秀的,我其實需要的是-117,我改變.offset()頂部+ 117)至 - 117它的工作很好。非常感謝 –

+0

嗯,這似乎有移動Safari瀏覽器的問題 – K2xL