javascript 在 jQuery mobile 中,tap 和 vclick 之间的区别是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15274809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 00:08:45  来源:igfitidea点击:

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

javascriptjqueryhtmlcssjquery-mobile

提问by lovespring

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

我应该使用哪个事件来收听?为什么要使用 vclick?我只是不知道在哪种情况下使用哪种。

回答by Gajotres

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

对于 jQuery Mobile Tap 过去只能在移动设备上工作。这已经不是这种情况了。

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

VClick 的创建是为了弥补桌面/移动设备之间点击/点击不兼容之间的差距。

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

现在,您可以随意使用 Tap,但几乎没有问题。在 iOS 平台上点击会失败。应改用 Touchstart。

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
  • Android 4.1.1 - 无延迟
  • iOS - 无延迟
  • 桌面版 Firefox 19 和 Chrome 25.0.1364.152 - 无延迟

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

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.

它曾经只适用于移动设备,现在也适用于桌面浏览器,但在 jQuery Mobile 1.1 及以下版本的 iOS 上会失败。

  • Android 4.1.1 - No delay
  • iOS - No delay
  • Desktop Firefox 19 & Chrome 25.0.1364.152 - No delay
  • Android 4.1.1 - 无延迟
  • iOS - 无延迟
  • 桌面版 Firefox 19 和 Chrome 25.0.1364.152 - 无延迟

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

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
  • Android 4.1.1 - 可见延迟(300+ 毫秒)
  • iOS - 无延迟
  • 桌面版 Firefox 19 和 Chrome 25.0.1364.152 - 无延迟

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

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.

如果您想要与VClick的向后 jQM 兼容性棒,在任何其他情况下使用Tap

回答by DalSoft

vclick (virtualized click) simulates the onclick event.

vclick(虚拟点击)模拟 onclick 事件。

http://api.jquerymobile.com/vclick/

http://api.jquerymobile.com/vclick/

Tap event triggers after a quick, complete touch event single target object.

在快速、完整的触摸事件单个目标对象后触发点击事件。

http://api.jquerymobile.com/tap/

http://api.jquerymobile.com/tap/

It depends what you are doing but unless you have a specific reason not to (e.g. supporting desktop and mobile with the same js) I would use tap.

这取决于您在做什么,但除非您有特定的理由不这样做(例如,使用相同的 js 支持桌面和移动设备),否则我会使用 tap。

More information here https://coderwall.com/p/bdxjzg

这里有更多信息https://coderwall.com/p/bdxjzg

回答by Jules

I've just noticed a major difference between 'tap' and 'vclick'. 'vclick' fires if you tab to a button and press the enter key - 'tap' does not.

我刚刚注意到“tap”和“vclick”之间的主要区别。如果您使用 Tab 键切换到按钮并按下 Enter 键,则会触发 'vclick' - 'tap' 不会。