2015-10-07 160 views
0

我爲我的網站使用固定頭,我有一個問題:當我使用錨鏈接時,第一個內容在標題下。 當我在頁面上,我可以使用腳本是這樣的:頭固定和錨鏈接

$('.action').click(function(event){ 
    event.preventDefault(); 
    $('html, body').animate({scrollTop:$('#projects').position().top - 60},800); 
}); 

但是當我另一個頁面,使用HREF =「#index.html的項目」的問題出來。

有一種解決方案允許使用不帶邊距的方法嗎?

謝謝!

+0

如果您創建類似的[demo](http://www.jsfiddle.net)則更好。 – divy3993

回答

0

這可能不是您的最佳解決方案,但我會告訴您我會做什麼。通常當我使用固定的頭部元素時,我也會創建一個固定的身體或內容元素。

<html> 
    <head> 
    </head> 
    <body> 
     <div id="header" style="position:fixed;top:0px;left:0px;right:0px;height:50px;"> 
      <!-- header html here --> 
     </div> 
     <div id="content" style="position:fixed;top:50px;left:0px;right:0px;bottom:0px;"> 
      <!-- content html here --> 
     </div> 
    </body> 
</html> 
+0

對於固定的內容元素,我無法向下滾動:S –

+0

添加了css'overflow:scroll;' – Andrew

+0

我認爲添加了css'top:-70px; padding-top:70px;'是更好的解決方案。謝謝你的幫助! –