我正在使用以下脚本在单页网站上启用平滑滚动。
对于导航,我使用固定的导航栏,它位于页面顶部的最上层 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
是你要滚动的 var
所以你所要做的就是在
$('html,body').animate({scrollTop:dest}, 1000,'swing');
或在这一行的执行范围内。
目标 - 108
我是一名优秀的程序员,十分优秀!