kee*_*web 6 javascript iphone jquery mobile-safari touch
如何防止Safari iOS中的过度滚动?我会使用触摸手势在网站上导航,但我不能.
我试过这个:
$(window).on('touchstart', function(event) {
event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
但是通过这种方式我禁用了所有手势,事实上我无法通过捏合和捏合来缩放.
有解决方案吗 谢谢.
小智 13
这种方式将允许可滚动元素,同时仍然防止浏览器本身的过度滚动.
//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();
});
Run Code Online (Sandbox Code Playgroud)
这应该是完成此任务的最简单方法:
$(function() {
document.addEventListener("touchmove", function(e){ e.preventDefault(); }, false);
});
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
最好.
| 归档时间: |
|
| 查看次数: |
17155 次 |
| 最近记录: |