ngryman / jquery.finger

:v: jQuery touch & gestures, fingers in the nose.
https://ngryman.sh/jquery.finger/
MIT License
423 stars 66 forks source link

Double tap event without firing tap event #39

Closed ro-savage closed 9 years ago

ro-savage commented 9 years ago

I would like to be able to have multiple tap events on a single element.

    $('#tapme').on('tap', function() {
        console.log('tapped!');
    });

    $('#tapme').on('doubletap', function() {
        console.log('Double tapped!');
    });

However, when I double tap, the tap event is fired instantly.

Could there be an option added to delay the single tap event from occurring? Then if it detected another tap within the 'doubleTapInterval' it would fire the doubleTap event only and never fire the original tap event. If it didn't register another tap within the 'doubleTapInterval' it would fire just the single tap event?

Basically adding in the 300ms delay again, as an option.

Thank

davidlevy commented 9 years ago

I have the same issue :( Apparently, HammerJS handles it pretty good : http://stackoverflow.com/questions/22683122/how-to-bind-tap-and-doubletap-to-the-same-element-in-hammer-js

Did you find a fix/hack @ro-savage ?

ngryman commented 9 years ago

Related to #22. Finger's goal is to keep KISS.

If you want to handle edge cases like this I would either advice to do it by yourself or eventually use another library (like Hammer) which resolves those issues, at the cost of a much larger size.

For your specific example, you could do something like this:

var tapTimeout;

$('button').on('tap', function() {
    tapTimeout = setTimeout(function() {
        $('body').append('<p>Click');
    }, 300);
});

$('button').on('doubletap', function() {
    clearTimeout(tapTimeout);
    $('body').append('<p>Double tap');
});