Sasha Grievus
Sasha Grievus

Reputation: 2686

How to respond to 'click' instead of 'swipe' on mobile in jquery?

I have this code, on a mobile page:

jQuery(document).ready(function($){
    $('a').on('click touchend', function(e) {
        /* Do something */
    });
});

works fine, but on mobile devices it's called both for click on links and on swipe (that is touching the link, scrolling and lifting the finger). How can I modify this to be called only on click?

I tried 'tap', 'click' and doesn't seem to work, nor I can find a good list of all the possibile events fired on mobile...

Upvotes: 0

Views: 254

Answers (3)

Sasha Grievus
Sasha Grievus

Reputation: 2686

On mobile devices, it seems that the first click on a menu is taken as an hover instead of a click, so the solution in my case was

jQuery(document).ready(function($){
    $('a').hover(function(e) {
        /* Do something */
    });
});

Upvotes: 0

Hamik Hambardzumyan
Hamik Hambardzumyan

Reputation: 187

Firstly you must recognize mobile or pc after that decide which type of event use.

example how you can recognize device here

Upvotes: 0

Diptox
Diptox

Reputation: 1809

jQuery(document).ready(function($){
    $('a').on('vclick', function(e) {
        /* Do something */
    });
});

Upvotes: 2

Related Questions