有没有办法触摸启动事件不会触发点击事件?

时间:2012-02-20 13:42:22

标签: javascript events touch mouse

如果访问者点击,则会触发click事件。但是,当有人触摸图片时,即使click事件也可用,也会触发相同的touchstart事件。

我喜欢实际点击(鼠标)事件和触摸事件的不同行为。奇怪的是,即使在智能手机上使用mouseup事件也会被触发。无论如何你可以将鼠标与触摸事件分开吗?

3 个答案:

答案 0 :(得分:9)

event.preventDefault();

诀窍,希望这有助于人们!

答案 1 :(得分:1)

您可以规范事件..

请参阅我对这个问题的回答:

Click event called twice on touchend in iPad

您还可以查看jQuery移动源代码以获取灵感: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;
});
....

查看点击事件:(第1049行)

$.event.special.tap = {

答案 2 :(得分:-1)

这是一种防止touchstart后点击的复杂方法。在touchstart之后传播的点击称为ghost click。

Google已实施解决方案。你去.. ..

http://code.google.com/mobile/articles/fast_buttons.html#ghost