[英]Adding a top-margin to smoothscroll
我正在使用以下腳本在一頁網站上啟用平滑滾動。
對於導航,我使用固定的導航欄,該導航欄位於頁面的最上方的z-index層上。 欄的最高高度為108像素,因此當我使用smoothscroller時,要導航到的部分區域被導航欄隱藏。
我差勁的JS技能使我除了咨詢你們中的某些人外別無選擇...我將如何在此腳本中添加108px的上邊距? 任何人?
$(".scroll").click(function(event){
event.preventDefault();
//calculate destination place
var dest=0;
if($(this.hash).offset().top > $(document).height()-$(window).height()){
dest=$(document).height()-$(window).height();
}else{
dest=$(this.hash).offset().top;
}
//go to destination
$('html,body').animate({scrollTop:dest}, 1000,'swing');
});
dest
是您要滾動的變量
因此,您要做的就是從中獲取一些價值
$('html,body').animate({scrollTop:dest}, 1000,'swing');
或在此行的執行范圍內。
目標-108
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.