如何在Safari iOS中防止过度滚动? 我想使用触摸手势在网站上导航,但是我无法实现。
我尝试了这个方法:
$(window).on('touchstart', function(event) {
event.preventDefault();
});
但是这样做将禁用所有手势,事实上我不能用捏合手势缩放。
有什么解决方案吗? 谢谢。
如何在Safari iOS中防止过度滚动? 我想使用触摸手势在网站上导航,但是我无法实现。
我尝试了这个方法:
$(window).on('touchstart', function(event) {
event.preventDefault();
});
但是这样做将禁用所有手势,事实上我不能用捏合手势缩放。
有什么解决方案吗? 谢谢。
这种方式可以让元素可以滚动,同时仍然防止浏览器本身的过度滚动。
//uses document because document will be topmost level in bubbling
$(document).on('touchmove',function(e){
e.preventDefault();
});
//uses body because jquery on events are called off of the element they are
//added to, so bubbling would not work if we used document instead.
$('body').on('touchstart','.scrollable',function(e) {
if (e.currentTarget.scrollTop === 0) {
e.currentTarget.scrollTop = 1;
} else if (e.currentTarget.scrollHeight === e.currentTarget.scrollTop + e.currentTarget.offsetHeight) {
e.currentTarget.scrollTop -= 1;
}
});
//prevents preventDefault from being called on document if it sees a scrollable div
$('body').on('touchmove','.scrollable',function(e) {
e.stopPropagation();
});
$(function() {
document.addEventListener("touchmove", function(e){ e.preventDefault(); }, false);
});