我想在滚动事件期间切换底部的菜单。所以我创建了一个固定菜单,它根据顶部的位置显示/隐藏。该事件目前仅在触摸时触发。手指离开设备后网页滚动时有什么方法可以触发事件吗?滚动事件在 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;
}
最佳答案
当您监听 touchstart
、touchmove
和 touchend
时,它当然也会在触摸时触发。我可能会尝试仅在滚动时触发它,并添加一些超时来查看滚动是否停止。
$(document).on("scroll", function() {
var position = $(document).scrollTop();
hideMenu();
setTimeout(function() {
if (position == $(document).scrollTop())
// We have stopped scrolling
showMenu();
}, 100);
});
关于javascript - 触摸结束后,是否有任何事件可以在 iOS 设备上使用 jQuery 检测动量滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31719923/