禁用iOS Safari中的过度滚动 [英] Disable overscroll in iOS Safari
本文介绍了禁用iOS Safari中的过度滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何防止Safari iOS中的过度滚动?
我会使用触摸手势在网站上导航但我不能。
How can I prevent overscroll in Safari iOS? I would use the touch gesture for navigate on a site but I can't.
我试过这个:
$(window).on('touchstart', function(event) {
event.preventDefault();
});
但是这样我禁用了所有手势,事实上我无法通过捏合和捏缩放-out。
But in this way I disabled all gesture, infact I can't zooming with pinch-in and pinch-out.
任何解决方案?
谢谢。
Any solutions? Thanks.
推荐答案
这种方式将允许可滚动元素,同时仍能阻止浏览器本身的过度滚动。
This way will allow scrollable elements while still preventing the overscroll in the browser itself.
//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();
});
这篇关于禁用iOS Safari中的过度滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文