2013-05-12 21 views
0

我試圖使用我如何滾動到#target - 100px?

<a href="#target">Details</a> 

<div id="target">asd...</div> 

,但我也有頂部的彈出菜單。所以它就在菜單後面。

是否有可能(還我已經使用引導和jQuery庫在我的模板)編寫JavaScript去#target - 100px

在此先感謝

回答

1

沒試過,但這樣的事情應該工作。

$('html, body').animate({ 
    scrollTop: $("#elementtoScrollToID").offset().top - 100 
}, 1000); // this is the time in millisecond of the animation 
0

一個簡單的JavaScript唯一的解決辦法是:

window.scrollTo(x,y) 

爲了您的例子中,你可以使用:

window.scrollTo(0,100) 
0
scrollTop: ($($anchor.attr('href')).offset().top)-300 

這是我的代碼和它的作品。 -300 =像素

相關問題