Is there a way that a touch start event will not trigger the click event?
Solution 1
event.preventDefault();
Did the trick, hope this helps people!
Solution 2
you can normalize an event..
See my answer to this question:
Click event called twice on touchend in iPad
You can also look in the jQuery mobile source code to find inspiration: http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.js Start at line 982
/*
* "events" plugin - Handles events
*/
(function( $, window, undefined ) {
// add new event shortcuts
$.each( ( "touchstart touchmove touchend orientationchange throttledresize " +
"tap taphold swipe swipeleft swiperight scrollstart scrollstop" ).split( " " ), function( i, name ) {
$.fn[ name ] = function( fn ) {
return fn ? this.bind( name, fn ) : this.trigger( name );
};
$.attrFn[ name ] = true;
});
....
Look at the tap event: (line 1049)
$.event.special.tap = {
Mark
Updated on June 13, 2022Comments
-
Mark almost 2 years
When a visitor clicks on an image the
click
event will be triggered. However when someone touches the image, that sameclick
event will be triggered, even if atouchstart
event is available as well.I like a different behavior for an actual click (mouse) event and a touch event. The strange thing is, even a
mouseup
event is triggered when used on a smartphone. Is there anyway you can separate the mouse from the touch events? -
Mark about 12 yearsThanks for the thorough answer. The only thing is, now you are targeting 'special devices specifically' in this case the iPhone. I rather want all devices that support touchstart to treat click and touchstart different. I wish there was a simple var you could set to disable.
-
Dan Tello almost 9 yearsThis won't work if you're just adding
event.preventDefault()
to thetouchstart
callback. At least not on links in iOS 8.4 Safari. You'd have to add it to theclick
event handler.