Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...