Javascript jQuery don';不要等到滚动停止才运行代码?
我的标题在滚动中显示/隐藏时出现问题。下面的代码几乎与预期的一样工作,唯一需要注意的是,它只在滚动停止时运行Javascript jQuery don';不要等到滚动停止才运行代码?,javascript,jquery,Javascript,Jquery,我的标题在滚动中显示/隐藏时出现问题。下面的代码几乎与预期的一样工作,唯一需要注意的是,它只在滚动停止时运行 $(window).scroll(function(e) { if (top.location.pathname === '/') { var scrollHeight = $(window).scrollTop(); var heroHeight = $("#home #hero").height(); if (scrollH
$(window).scroll(function(e) {
if (top.location.pathname === '/') {
var scrollHeight = $(window).scrollTop();
var heroHeight = $("#home #hero").height();
if (scrollHeight >= heroHeight) {
$('.navbar').css("display", "block");
$('.navbar').stop().animate({
top: 0
}, 200);
} else {
$('.navbar').stop().animate({
top: "-50px"
}, 200);
}
}
});
如果高度大于
heroHeight
的高度,该功能将无法运行,您有什么想法吗?请尝试$(窗口)。在(“滚动”上,功能(e)可以console.log(滚动高度)
和console.log(heroHeight)
?在代码中找不到任何错误。@AJFMEDIA同样的效果,这只在使用mac触控板时发生。