javascript 有没有办法让触摸开始事件不会触发点击事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9362119/
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
Is there a way that a touch start event will not trigger the click event?
提问by Mark
When a visitor clickson an image the click
event will be triggered. However when someone touches the image, that same click
event will be triggered, even if a touchstart
event is available as well.
当访问者单击图像时,click
将触发该事件。但是,当有人触摸图像时click
,即使touchstart
事件也可用,也会触发相同的事件。
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?
我喜欢实际点击(鼠标)事件和触摸事件的不同行为。奇怪的是,mouseup
在智能手机上使用时甚至会触发事件。无论如何,您可以将鼠标与触摸事件分开吗?
回答by Mark
event.preventDefault();
Did the trick, hope this helps people!
成功了,希望这对人们有所帮助!
回答by andlrc
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.jsStart at line 982
您也可以查看 jQuery mobile 源代码以寻找灵感:http: //code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.js从第 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)
看一下tap事件:(第1049行)
$.event.special.tap = {
回答by Hasanavi
It is a complex way to prevent click after touchstart. The click which propagates after touchstart is called ghost click.
这是一种防止在 touchstart 后点击的复杂方法。在 touchstart 之后传播的点击称为幽灵点击。
Google has implemented a solution. Here you go..
谷歌已经实施了一个解决方案。干得好..
http://code.google.com/mobile/articles/fast_buttons.html#ghost
http://code.google.com/mobile/articles/fast_buttons.html#ghost