[英]Adding a top-margin to smoothscroll
I am using the following script to enable smoothscrolling on a one-page site. 我正在使用以下脚本在一页网站上启用平滑滚动。
For navigation I use a fixed navigation bar that sits on top of the page on a uppermost z-index layer. 对于导航,我使用固定的导航栏,该导航栏位于页面的最上方的z-index层上。 The hight of the bar is 108px, so when I use the smoothscroller, part of the section I want to navigate to gets hidden by the nav-bar. 栏的最高高度为108像素,因此当我使用smoothscroller时,要导航到的部分区域被导航栏隐藏。
My poor JS skills leaves me no other option than to consult some of you guys... how would I add a 108px top-margin to this script? 我差劲的JS技能使我除了咨询你们中的某些人外别无选择...我将如何在此脚本中添加108px的上边距? anyone? 任何人?
$(".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
is your var to scroll dest
是您要滚动的变量
so all you have to do is take some values off from it before 因此,您要做的就是从中获取一些价值
$('html,body').animate({scrollTop:dest}, 1000,'swing');
or within the execution of this line. 或在此行的执行范围内。
dest - 108 目标-108
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.