我在頁面的頂部有一個浮動的導航欄,所以當我點擊#ID鏈接時,它隱藏了我想要滾動到它後面的對象。jquery滾動到設置值以上的div
我使用此代碼滾動的jQuery:
<script>
$(function() {
$('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
}, 1000);
return false;
}
}
});
});
</script>
有沒有一種方法,我可以滾動的像素設置量稍低於或高於標籤的位置更高?
注意:請一定要允許因爲一些jQuery的的鍍鉻「不安全內容」,否則不會工作。
是的,這就是我的意思。這個問題已經得到解答,正在等待接受...... – 2014-10-06 22:21:17