iOS Safari 标志用于停止页面移动?
我很好奇是否有人找到了一种解决方案,可以在用户在页面上拖动手指时禁用默认的弹簧加载 iOS 页面移动。对于完全可见的页面(即不需要滚动),页面会移动并弹回原位。
我发现禁用“touchstart”可以有效地解决此问题,但它会破坏所有点击事件!?!例如:
document.addEventListener('touchstart', function(e) {
e.preventDefault();
}, false);
我尝试过其他触摸/鼠标事件,但没有运气。我猜有人知道一个秘密的 webkit CSS 或 JavaScript 属性可以禁用此功能。
编辑:作为我正在寻找的示例,这里有一个通过 CSS 禁用其他默认 iOS Webkit 行为的类似答案。不幸的是,这些似乎不适用于我的问题:
I'm curious if anyone has found a solution to disabling the default spring-loaded iOS page move when a user drags their finger across the page. For pages that are completely visible (i.e., no scrolling is necessary) the page moves and springs back into place.
I've found that disabling the "touchstart" will effectively fix this, but then it breaks all click events!?! For example:
document.addEventListener('touchstart', function(e) {
e.preventDefault();
}, false);
I've tried other touch / mouse events but no luck. I'm guessing someone out there knows a secret webkit CSS or JavaScript property which can disable this feature.
Edit: as an example of what I'm looking for, here is a similar answer for disabling other default iOS Webkit behaviors via CSS. Unfortunately these don't seem to apply to my question:
Prevent default Press but not default Drag in iOS MobileSafari?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我本可以发誓我尝试过这个,但看来“touchmove”能解决这个问题吗?
更新:经过更多测试,是的,这确实有效。似乎人们永远不应该在“touchstart”上使用 e.preventDefault(),因为这也会阻止随后发生的所有其他鼠标事件。
I could have sworn I tried this, but it appears "touchmove" does the trick?
Update: After more testing, yes this does in fact do the trick. It seems as though one should never e.preventDefault() on 'touchstart' as that also prevents all other mouse events that follow.