如何从正文中反转 e.preventDefault() ?
我有这个:
function dontMove(event) {
// Prevent page from elastic scrolling
event.preventDefault();
}
&
<body ontouchmove="dontMove(event);">
在 ipad 上,这会阻止它被拖动,并且当您拖动整个页面时,不允许 ipad 出现灰色背景。
我在另一个网站上看到,可以在另一个 div 中反转它,以便该 div 再次完全可拖动。
有谁知道如何扭转它?
我也尝试使用它来防止它(在 document.ready 中):
document.ontouchmove = function(e){
e.preventDefault();
}
&启用它:
function doTouchMove(state) {
document.ontouchmove = function(e){
return state;
}
}
然后我输入它来激活它。
<img ontouchmove="doTouchMove(state);" src="../jpeg/pages/01.jpg" class="touch"/>
这似乎不起作用 这有什么问题吗? 或者任何其他可能有效的方法?
I have this:
function dontMove(event) {
// Prevent page from elastic scrolling
event.preventDefault();
}
&
<body ontouchmove="dontMove(event);">
This, on the ipad, stops it from being draggable and does not allow that grey background the ipad has when you drag a whole page around to show up.
I have seen on another website that its possible to reverse that in another div, so that div is completely draggable again.
Does anyone know how to reverse it?
I have also tried using this to prevent it (in the document.ready):
document.ontouchmove = function(e){
e.preventDefault();
}
& this to enable it:
function doTouchMove(state) {
document.ontouchmove = function(e){
return state;
}
}
Then I put this to activate it.
<img ontouchmove="doTouchMove(state);" src="../jpeg/pages/01.jpg" class="touch"/>
This didn't seem to work
Is there anything wrong with this?
Or any other way that might work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这正是为什么
bubbles
稍微好一点的原因(至少在我看来)。bubbles
是跨浏览器的,所以你应该能够替换。使用
在代码中
和 后面的内容,您可能会将
bubbles
重置为true
。如果以上不是一个选项,则忽略即可。 :D另一种选择(如果您只使用 iPad)是反转 DOM 的工作方式。
这将迫使事件向另一个方向发展。
This is exactly why
bubbles
is slightly better(at least in my opinion).bubbles
is cross browser, so you should be able to replace.with
and then latter in your code, you could potentially reset
bubbles
totrue
.If the above isn't an option then just ignore. :D
An alternative(if you are just working with an iPad) is to just reverse how the DOM works.
This will force the event to work in the other direction.
尝试这篇文章,带有 event.preventDefault 的 HTML 并从中删除 ontouchmove身体标签。
我的看起来像这样
,然后在你想要的每个标签上启用 ontouchmove 。 IE:
try this post, HTML with event.preventDefault and erase ontouchmove from body tag.
Mine looks like this
then enable ontouchmove on every tag you want. ie:
我设法解决了它
I managed to solve it with
您可以通过仅阻止来自主体的事件来解决此问题:
You can solve it by preventing the event only if it comes from the body: