问题:我想完成以下动画:当页面在移动设备中加载时,我想显示ID为“sub-header”的div,但只要用户滚动超过50px的页面我想要隐藏子标题。页面隐藏菜单,但是当我向上滚动,它显示和隐藏多:最后,如果用户向上滚动60像素,而随时在页面上我想子头.show基于滚动位置显示/隐藏子标题
我所用下面的代码看我停止滚动后的时间。
JQuery的:
var newScroll = 0;
var subHeaderPosition = true;
var currentScroll = 0;
$(window).scroll(function() {
currentScroll = $(window).scrollTop();
if ($(window).width() < 779) {
if (currentScroll > 50 && subHeaderPosition) {
console.log("Current Scroll position: " + currentScroll);
console.log("Scroll should hide");
$("#sub-header").hide(300);
subHeaderPosition = false;
newScroll = $(window).scrollTop();
console.log("New Scroll position: " + newScroll);
} else if ((currentScroll - 60) < newScroll && !subHeaderPosition) {
console.log("Scroll position: " + currentScroll);
console.log("Scroll should show Sub-Header");
$("#sub-header").show(300);
subHeaderPosition = true;
newScroll = $(window).scrollTop();
} else {
newScroll = $(window).scrollTop();
}
}
});
UPDATE:增加了更多的日志后,我现在可以告诉大家,我的newscroll和currentscroll总是碰得指向我朝着正确的方向相同的号码。一旦我拥有了它,我会发布一个解决方案,或者如果有人知道它,我就会全神贯注。
不幸的是,我想要“标题显示,如果用户开始向上滚动不只是当他们到达页面的顶部。 – Denoteone