Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In jQuery mobile, what's the diff between tap and vclick?

which event should i use to listen to ? why use vclick? and I just don't know which situation to use which.

like image 978
lovespring Avatar asked Mar 07 '13 15:03

lovespring


People also ask

Does click function work in mobile?

click() is not working on some Android devices (it works but have to click twice…) this is for standard nav show/hide that is used in mobile devices…

What is difference between click and Onclick in jQuery?

So onclick creates an attribute within the binded HTML tag, using a string which is linked to a function. Whereas . click binds the function itself to the property element.

Does jQuery work on mobile?

Supported PlatformsjQuery Mobile has broad support for the vast majority of all modern desktop, smartphone, tablet, and e-reader platforms.

Is jQuery Mobile outdated?

jQuery Mobile is no longer supported.


1 Answers

In case of jQuery Mobile Tap used to work only on mobile devices. This is not case any more.

VClick was created to bridge a gap between click/tap incompatibility among desktop/mobile devices.

Now days you case freely use tap but there are few problems. Tap will fail on iOS platform. Touchstart should be used instead.

Examples:

VClick

Will work both on desktop and mobile devices.

  • Android 4.1.1 - No delay
  • iOS - No delay
  • Desktop Firefox 19 & Chrome 25.0.1364.152 - No delay

http://jsfiddle.net/Gajotres/PYPXu/embedded/result/

$(document).on('pagebeforeshow', '#index', function(){       
    $( document ).on( "vclick", '[data-role="page"]', function() {
        $( this ).append( "<span style='color:#00F;'>vmouseup fired.</span>" );
    });
});

Tap:

Tap

It used to work only on a mobile devices, now works also on a desktop browsers, but will fail on a iOS with a jQuery Mobile version 1.1 and below.

  • Android 4.1.1 - No delay
  • iOS - No delay
  • Desktop Firefox 19 & Chrome 25.0.1364.152 - No delay

http://jsfiddle.net/Gajotres/k8kSA/

$(document).on('pagebeforeshow', '#index', function(){       
    $( document ).on( "tap", '[data-role="page"]', function() {
        $( this ).append( "<span style='color:#00F;'>tap fired.</span>" );
    });
});

Click

Will work on mobile devices and desktop browsers.

  • Android 4.1.1 - Visible delay (300+ ms)
  • iOS - No delay
  • Desktop Firefox 19 & Chrome 25.0.1364.152 - No delay

http://jsfiddle.net/Gajotres/L2FHp/

$(document).on('pagebeforeshow', '#index', function(){       
    $( document ).on( "click", '[data-role="page"]', function() {
        $( this ).append( "<span style='color:#00F;'>click fired.</span>" );
    });
});

Conclusion

If you want a backward jQM compatibility stick with VClick, in any other case use Tap.

like image 193
Gajotres Avatar answered Oct 11 '22 19:10

Gajotres