2013-12-21 17 views
0

我想調整滾動時使用錨點的位置,因爲我使用粘滯標題和錨點位置似乎基於自身的頂部即使我在主頁div上有css padding,這個頁面本身可以工作,但是當我點擊一個錨點時,它不能正常工作。使用jquery調整錨定目標的位置,以考慮粘滯標題

我把這個平滑滾動碼只要錨鏈接從頁面本身來,但它沒有任何效果,當我從另一個頁面

$('a[href*=#]:not([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) { 
       $('html,body').animate({ 
       scrollTop: (target.offset().top - 120) 
      }, 1000); 
      return false; 
     } 
    } 
}); 
直接導航到錨的正常工作

任何人都可以幫助我得到這個工作,所以它是相同的,無論點擊來自另一個頁面或錨內的頁面。

回答