2016-05-29 75 views
-1

我有以下鏈接:http://www.alessandrosantese.com/test/aldemair-productions/project.htmljQuery的滾動到錨無法正常工作

,我使用這個滾動到一個id一個特定的div:

 $('.project-nav a').on('click', function(e){ 
      e.preventDefault(); 

      var anchor = $(this).attr('data-id'), 
      el = $('#' + anchor); 
      $('html, body').animate({ scrollTop: el.offset().top}, 500); 

     }); 

它的工作原理差不多吧,它不在正確的位置滾動,他們似乎都是不正確的。

如果您點擊詳細信息,您將在上方滾動例如。

回答

1

你應該嘗試:

$('html, body').animate({ scrollTop: el.offset().top - $('header.close').height()}, 500); 

的滾動工作正常。如果您隱藏標題,您會看到「詳細信息」完全位於窗口頂部...