user701510
user701510

Reputation: 5773

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. 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?

This sums up my thought process:

  1. Jquery is built on base functionality of vanilla Javascript
  2. base functionality of vanilla Javascript does not support touch events; therefore, Jquery does not support touch events
  3. conclusion: in order for Jquery to support touch events, vanilla Javascript must incorporate touch events?

Upvotes: 1

Views: 3232

Answers (2)

nnnnnn
nnnnnn

Reputation: 150070

Not sure what your question is, and your point 2 seems to disagree with your point 3, but anyway...

Touch events are supported by at least some browsers and devices:

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

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

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

Upvotes: 1

mamoo
mamoo

Reputation: 8166

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

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. 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.

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

Upvotes: 2

Related Questions