Mobile Safari 触摸事件捕获问题

发布于 2024-10-04 03:26:46 字数 439 浏览 1 评论 0原文

我有一个在 iPad 上的 Safari 上运行的移动网络应用程序。

看起来,即使网页的尺寸适合屏幕,拖动页面仍然会使其滚动部分屏幕。

我的计划是防止任何未处理的触摸事件执行任何操作:

document.addEventHandler('touchstart', do_nothing, false);

function do_nothing(event) {
    event.preventDefault();
}

请注意最后的 false 参数 - 这应该告诉处理程序仅在事件冒泡模式下工作,而不是在捕获模式下工作。特定元素上的触摸事件仍应按预期触发。

确实阻止了滚动。但是,它也会阻止任何点击事件到达页面。任何人都可以提出一种解决方案来阻止默认页面滚动操作而不阻止点击吗?

I have a mobile web-app running on Safari on an iPad.

It seems that even though the web page is the right size for the screen, dragging the page still makes it scroll partially of screen.

My plan had been to prevent any otherwise unhandled touch event from doing anything:

document.addEventHandler('touchstart', do_nothing, false);

function do_nothing(event) {
    event.preventDefault();
}

Note the final false parameter - this is supposed to tell the handler to only work in event bubbling mode, not capture mode. A touch event on a specific element should still fire as expected.

This does prevent the scrolling. However it also prevents any click events from reaching the page. Can anyone propose a solution that blocks the default page scroll action without also blocking clicks?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疧_╮線 2024-10-11 03:26:46

解决方案似乎是在 touchmove 上注册 null 处理程序,而不是在 touchstart 事件上注册。

The solution appears to be to register the null handler on the touchmove instead of the touchstart event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文