禁用滚动网页iPad [英] Disable Scrolling Web Page iPad
问题描述
我见过许多涉及停止所有touchmove事件的解决方案。但是这对我来说不起作用,因为我的应用程序涉及绘图画布。有没有办法确保用户不能滚动,同时保留其他touchevents?
--Ashley
I've seen a lot of solutions involving stopping all touchmove events. 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
推荐答案
您可以使用 e.preventDefault()
在您的绘图处理程序中,或者在DOM树中进一步附加的处理程序中。这只是阻止了要滚动的 touchmove
的默认行为。
You can use e.preventDefault()
in your drawing handlers, or in a handler attached further up the DOM tree. This just prevents the default behaviour of the touchmove
which is to scroll.
$('body, html').on('touchmove', function(e){
e.preventDefault();
});
你仍然可以处理 touchmove
绘图画布上的事件。
You'll still be able to handle touchmove
events on your drawing canvas.
另一种选择是在你的CSS中设置 overflow:hidden
- 但是这个取决于您的网页大小。
Another option would be to set overflow:hidden
in your CSS - but this depends on the size of your page.
这篇关于禁用滚动网页iPad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!