在触摸手机上使用 Javascript 检测手指拖动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7287439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detect finger drag using Javascript on touch phones?
提问by Ivan
Is there a way to detect finger drags using Javascript on touch phones? I'm currently using jQuery and the mousemove() method doesn't appear to work on my Andorid phone.
有没有办法在触摸手机上使用 Javascript 检测手指拖动?我目前正在使用 jQuery,并且 mousemove() 方法在我的 Andorid 手机上似乎不起作用。
EDIT:I suppose I should clarify that this is for a web application.
编辑:我想我应该澄清一下这是针对 Web 应用程序的。
EDIT 2:I found a duplicate of my question a few moments ago: Detect a finger swipe through JavaScript on the iPhone and Android. Although, it does not have an accepted answer.
编辑 2:我刚才发现了我的问题的副本:Detect a finger swipe through JavaScript on the iPhone and Android。虽然,它没有一个公认的答案。
采纳答案by Matt Ball
Use the analogous touch events: touchstart
, touchmove
, touchcancel
, and touchend
. To bind an event listener for one of these events, you'll have to use, for example .bind('touchmove', ...)
instead of .touchmove(...)
, because jQuery does not provide convenience methods.
使用类似的触摸事件:touchstart
,touchmove
,touchcancel
,和touchend
。要为这些事件之一绑定事件侦听器,您必须使用,例如.bind('touchmove', ...)
代替.touchmove(...)
,因为 jQuery 不提供方便的方法。
回答by SimplGy
You could use a touch library like https://github.com/dotmaster/Touchable-jQuery-Plugin
您可以使用像https://github.com/dotmaster/Touchable-jQuery-Plugin这样的触摸库
This is lightweight if paired with a lightweight dom abstraction library like the very-similar-to-jquery Zepto: http://zeptojs.com/
如果与非常类似于 jquery Zepto 的轻量级 dom 抽象库配对,则这是轻量级的:http: //zeptojs.com/