我有这个JQuery函数,我希望它滚动到positation-60px,因为我有一个固定的导航条,它与内容重叠。如何将这60 to添加到此代码中?
/**
* Scroll to section
* @param string des HTML identity of section block
* @return void
*/
function goToSectionID(des){
var os = (history.pushState)?51:0;
os = (jQuery(window).width()>800)?os:0;
var pos = (jQuery(des).length>0 )?jQuery(des).offset().top-os:0;
onanimate = true;
jQuery('html,body').animate({scrollTop:pos},1000,function(){
if(history.pushState){
history.pushState(null,null,des);
}else window.location.hash = des;
jQuery(window).scrollTop(pos);
onanimate=false
});
}发布于 2016-10-19 19:34:13
该函数过于复杂,或过于简单化,视情况而定,但我们尚未看到您的代码。
最简单的方法:
$(".arrowimg").click(function () {
$('html, body').animate({
scrollTop: $('#in').offset().top += 500
},500);
});第一行显然是eventListener和处理程序。第二行,目标html和主体跨浏览器的原因。使用动画方法。ScrollTop,然后是ID定位符的目标,如这里所示
<div class="arrowimg" id="in"></div>然后,我不知道您想要往上还是往下走60 px,因为我们还没有您的代码,但这是一个+或-的问题。
这是链接
http://codepen.io/damianocel/pen/zBLEXR
https://stackoverflow.com/questions/40136621
复制相似问题