使用javascript检测滑动手势 [英] Detect swipe gesture using javascript

查看:102
本文介绍了使用javascript检测滑动手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用javascript检测滑动手势。我不想使用一个单独的库,因为我有我的javascript回调的事件对象,我拥有我需要的一切,如deltaX,deltaY& absDeltaX& absDeltaY。我的问题是需要设置哪些限制,以便我可以区分滑动手势和其他手势,如滚动。

这是一个问题,因为有时候,当用户试图在屏幕上滑动时,他们也会创建一个显着的Y位移,这样就可以在滑动时将手势检测为滚动。

解决方案

我会看到这是一个判断电话,什么感觉可用?我会研究标准库使用的算法。例如,我们在jQuery文档中看到手势的规则被解释为滑动:


当水平拖动30px或更多(小于75px垂直)
发生在1秒内持续时间:


而且jQuery允许配置这些参数,这意味着没有,单一的正确答案。


Hi I want to know how I can detect a swipe gesture using javascript. I dont want to use a separate library for this since I have the event object from my javascript callback at my disposal, which has everything I need such as deltaX, deltaY & absDeltaX & absDeltaY. My problem is what bounds do I need to set so that I can differentiate a swipe gesture from other gestures such as scrolling.

This is a problem because sometimes when a user tries to swipe across the screen they also create a significant Y displacement which leads to the gesture also being detected as a scroll when it is only swipe.

解决方案

I would see this as a judgement call, what feels usable? I would investigate the algorithms used by standard libraries. For example we see in the jQuery documentation the rules for a gesture being interpreted as a swipe:

when a horizontal drag of 30px or more (and less than 75px vertically) occurs within 1 second duration:

And jQuery allows those parameters to be configured, implying that there's no, single, "correct" answer.

这篇关于使用javascript检测滑动手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆