在我的网站中,我制作了粘性标题。
它在所有浏览器上都运行良好,但当我在 Chrome 上的 Macbook 上测试时,scrollTop
我有我的主标题和一个粘性标题:
我这样编码:
$(document).on('scroll',function() {
if ($(document).scrollTop() >= 150) {
$('header:not(.sticky)').hide();
$('header.sticky').show();
} else {
$('header:not(.sticky)').show();
$('header.sticky').hide();
}
});
当我滚动到 150 像素时,它会跳转到我的页面顶部。
感谢您的帮助!
最佳答案
这在 Mac 机器的 Chrome 中运行良好
$(document).scroll(()=> {
if($(this).scrollTop()>= 150) {
//Your Actions
}
else {
//Your Actions
}
});
关于javascript - ScrollTop bug jquery 在 chrome 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45305529/