[英]Disable Scrolling Web Page iPad
I've seen a lot of solutions involving stopping all touchmove events. 我已经看到了很多解决方案,其中包括停止所有touchmove事件。 However this won't work for me, as my app involves a drawing canvas.
但是,这对我不起作用,因为我的应用程序包含一个绘图画布。 Is there a way to ensure that users can't scroll, while preserving other touchevents?
有没有一种方法可以确保用户在保留其他触摸事件的同时不会滚动? --Ashley
-阿什利
You can use e.preventDefault()
in your drawing handlers, or in a handler attached further up the DOM tree. 您可以在绘图处理程序中或在DOM树上方附加的处理程序中使用
e.preventDefault()
。 This just prevents the default behaviour of the touchmove
which is to scroll. 这只是防止了
touchmove
滚动的默认行为。
$('body, html').on('touchmove', function(e){
e.preventDefault();
});
You'll still be able to handle touchmove
events on your drawing canvas. 您仍然可以在绘图画布上处理
touchmove
事件。
Another option would be to set overflow:hidden
in your CSS - but this depends on the size of your page. 另一种选择是在CSS中设置“
overflow:hidden
-但这取决于页面的大小。
I think you should look to this answer.. Prevent touchmove default on parent but not child 我认为您应该查看此答案。. 防止在父级而不是子级上使用touchmove default
Put your canvas in a container and stop scrolling on the parent. 将画布放在容器中,然后停止在父级上滚动。
$('body').delegate('#fix','touchmove',function(e){
e.preventDefault();
}).delegate('.scroll','touchmove',function(e){
e.stopPropagation();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.