Is it possible to recognize touch events on the iPad's Safari browser using jQuery?
I used mouseOver and mouseOut events in a web application. Are there any similar events for the iPad's Safari browser since there are no events like mouseOut, mouseMove?
You can use .on() to capture multiple events and then test for touch screen, e.g.:
I know I am a little late on this but just tested benmajor's GitHub jQuery Touch Events plugin for both 1.4 and 1.7+ versions of JQuery. It is lightweight and works perfectly with both
on
andbind
while providing support for an exhaustive set of touch events.If you're using jQuery 1.7+ it's even simpler than all these other answers.
The simplest approach is to use a multitouch JavaScript library like Hammer.js. Then you can write code like:
And you can keep going. It supports tap, double tap, swipe, hold, transform (i.e., pinch) and drag. The touch events also fire when equivalent mouse actions happen, so you don't need to write two sets of event handlers. Oh, and you need the jQuery plugin if you want to be able to write in the jQueryish way as I did.
Using touchstart or touchend alone is not a good solution, because if you scroll the page, the device detect it as touch or tap too. So, the best way to detect a tap and click event at the same time is to just detect the touch events which are not moving the screen(scrolling). So to do this just add this code to your application:
I tested it and it works fine for me on iPad and iPhone. It detects tap and can distinguish tap and touch scroll easily.
Core jQuery doesn't have anything special for touch events, but you can easily build your own using the following events
For example, the
touchmove
This works in most webkit based browsers (incl. android).
Here is some good documenation: