简体   繁体   English

jQuery如何为移动设备实现触摸事件?

[英]How would jquery implement touch events for mobile devices?

This is more of a conceptual question. 这更多是一个概念上的问题。 After reading about Jquery Mobile, it got me thinking about how one would implement touch events like "tap" or "rub" using plain javascript. 在阅读了关于Jquery Mobile之后,它让我思考如何使用普通的javascript实现触摸事件,如“tap”或“rub”。 Since Jquery Mobile is built on javascript, does that mean the Jquery team is able to add custom events to vanilla javascript like ontap or ondrag ? 由于Jquery Mobile是基于javascript构建的,这是否意味着Jquery团队能够将自定义事件添加到像ontapondrag这样的vanilla javascript中?

This sums up my thought process: 这总结了我的思考过程:

  1. Jquery is built on base functionality of vanilla Javascript Jquery建立在vanilla Javascript的基本功能之上
  2. base functionality of vanilla Javascript does not support touch events; vanilla的基本功能Javascript不支持触摸事件; therefore, Jquery does not support touch events 因此,Jquery不支持触摸事件
  3. conclusion: in order for Jquery to support touch events, vanilla Javascript must incorporate touch events? 结论:为了让Jquery支持触摸事件,vanilla Javascript必须包含触摸事件?

Some mobile browsers are able to fire events related to the interaction with a touch screen. 一些移动浏览器能够触发与触摸屏交互相关的事件。 Mobile Safari (don't know about other mobile browser but things shouldn't change much) for example has some custom events like touchstart , touchmove or touchend 移动Safari(不了解其他移动浏览器,但应该不会有太大变化)例如具有一些自定义事件,例如touchstarttouchmovetouchend

http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html

That's how jQuery mobile and other libraries are able to handle this kind of events. 这就是jQuery mobile和其他库能够处理此类事件的方式。 If you want to dig deeper into a simple "real-world" implementation of one of this event you can have a look at the source code of this library, which handles the 'swipe' event. 如果您想深入了解此事件之一的简单“现实世界”实现,则可以查看该库的源代码,该库处理“ swipe”事件。

https://github.com/cubiq/SwipeView/blob/master/src/swipeview.js https://github.com/cubiq/SwipeView/blob/master/src/swipeview.js

Not sure what your question is, and your point 2 seems to disagree with your point 3, but anyway... 不确定您的问题是什么,而您的观点2似乎与观点3不同,但无论如何...

Touch events are supported by at least some browsers and devices: 至少某些浏览器和设备支持触摸事件:

https://developer.mozilla.org/en/DOM/Touch_events https://developer.mozilla.org/en/DOM/Touch_events

http://www.quirksmode.org/mobile/advisoryTouch.html http://www.quirksmode.org/mobile/advisoryTouch.html

http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM