Jquery Swipe without jQuery mobile library

20,558

If it's just jQuery mobile which you don't want to use, try hammer js which is lightweight and has a lot of options.

If however you're completely opposed to using any library at all have a look at the different touch events available:

https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Touch_events

Share:
20,558

Related videos on Youtube

Alan A
Author by

Alan A

Updated on January 30, 2020

Comments

  • Alan A
    Alan A over 4 years

    I know that this subject has been covered extensively on Stackoverflow but I cannot find a definitive answer.

    I am successfully detecting if the client device is a touch screen:

    if(!!('ontouchstart' in window)){
    
         // detect swipe
    
    }
    

    However, I cannot figure out how to detect a swipe/hover over an element. Please note that I want to be able to do this without the jquery mobile library.

    Here is my fiddle:

    http://jsfiddle.net/k77aC/9/

    Thank you in advance,

    Alan.

  • Alan A
    Alan A over 10 years
    Thanks hammer.js looks perfect for my needs!
  • Alan A
    Alan A over 10 years
    I don't seem to be able to detect a swipe or tap using hammer.js: $('.myElement').hammer().on("tap", ".nested_el", function(event) { alert('yes'); });
  • Alan A
    Alan A over 10 years
    I fixed it by referencing the id rather than the class