iPhone Web 应用程序 - 触摸和手势事件

发布于 2024-11-30 06:18:13 字数 404 浏览 0 评论 0原文

查看苹果网站和互联网上有关触摸和手势 JavaScript 事件的(相当过时的)文档,我不禁注意到在调用函数期间返回的手势事件仅包含值“scale” ”和“旋转”。我是否错过了某些内容,或者它们是唯一返回的两个值?

在 iPhone 上很难看到返回对象的值,因为它们只显示为类型和名称,这很烦人。例如,当在控制台中记录返回的对象时,它仅显示为“[object TouchEvent]”。

我想要实现的目标是在发生两根手指滑动时运行一个函数,然后无论滑动是向左还是向右,都会相应地更改页面。

我尝试了更复杂的触摸事件和(我认为会更容易的)手势事件,但手势事件仅返回缩放和旋转(显然),并且触摸事件在我这样做的方式上似乎相当复杂。

有谁知道返回的对象是否只是缩放和旋转,如果是,你知道我如何用 touchevent 获得相同的效果吗?

looking at the (quite outdated) documentation on the apple website and across the internet for the touch and gesture javascript events, I can't help but notice that the gesture event which is returned during the function being called, only contains the values 'scale' and 'rotation'. Have I missed something or are they the only two values returned?

It's hard to see the values of a returned object on the iPhone as they are annoyingly only shown as their type and name. e.g when logging the returned object in the console, it just shows up as '[object TouchEvent]'.

What I am trying to achieve is to run a function once a two finger swipe occurs, then whether the swipe was left or right, change the page accordingly.

I have tried a more complex touchevent and the (what I thought would be easier) gestureevent, but the gestureevent only returns the scale and rotation (apparently), and the touchevent seems quite complex in the way I am doing it.

Does anyone know if the object returned is just the scale and rotation, and if so, do you know how I can get the same effect with the touchevent instead?

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

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

发布评论

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

评论(1

送君千里 2024-12-07 06:18:13

您应该使用为您提供[运动]轨迹的 touchevent 来使用您自己的滑动定义来检测该轨迹是否属于“滑动”类别。

通常“滑动”手势是特定于上下文的:例如,它应该从特定的 DOM 元素开始,并可能在那里结束。这意味着对于特定的 DOM 元素,某些手势不是“滑动”,但对于其容器来说,例如它是滑动。所以一般来说你不能为此生成冒泡事件。

无需了解上下文即可检测缩放和旋转手势 - 因此系统会为您生成它们。

有带有滑动手势检测器的现成框架和库。至少对于一些流行的容器来说,例如垂直列表中的项目等。

You should use touchevent that provides you trajectory [of movements] to detect is this trajectory falls into "swipe" category using your own definition of swipe.

Usually "swipe" gesture is context specific: e.g. it should start in particular DOM element and probably end there. It means that for particular DOM element some gesture is not a "swipe" but for its container for example it is a swipe. So you cannot generate bubbling event for that in general.

Zoom and rotation gestures can be detected without knowing context - so system generates them for you.

There are ready to use frameworks and libraries that have swipe gesture detectors. At least for some popular containers like items in vertical list and so on.

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