我想在滚动事件期间在底部切换菜单。所以我创建了一个固定的菜单,根据它从顶部的位置显示/隐藏。该事件目前仅在触摸期间触发。手指从设备上抬起后,当网页滚动时,是否有任何方法可以触发事件?滚动事件在Android设备上运行良好。
function toggleMenu() {
if ($('.menu').offset().top < $('.fixed-menu').offset().top + 32) {
$('.fixed-menu').css('visibility', 'hidden');
} else {
$('.fixed-menu').css('visibility', 'visible');
}
}
$(window).on("load resize scroll touchstart touchmove touchend", function (e) {
toggleMenu();
});
html, body {
height: 100%;
-webkit-overflow-scrolling: touch;
overflow-y: scroll;
}
答案 0 :(得分:-1)
当您正在倾听touchstart
,touchmove
和touchend
时,它当然也会触发。我可能会尝试仅在scroll
上触发它,并添加一些timeOut以查看滚动是否已停止。
$(document).on("scroll", function() {
var position = $(document).scrollTop();
hideMenu();
setTimeout(function() {
if (position == $(document).scrollTop())
// We have stopped scrolling
showMenu();
}, 100);
});