2

How can I achieve to let jQuery/JavaScript perform a jQuery-Function if a mobile-user swipes with one finger to the left an another function if he swipes to the right?

I like to animate scrollLeft and scrollRight to a certain position if the user swipes left/right. I'm doing the same for desktop with keyboard-navigation trough Arrow Left/Right which works perfectly. Now I need the same for swiping on touch devices.

(if possible without jQuery Mobile or another additional library)

albuvee
  • 2,744
  • 6
  • 28
  • 38

2 Answers2

2

ok heres a long answer but it worth it:

jQuery (Swipe vs. Touch) pageX and pageY keep returning 0

Hope it helps

Community
  • 1
  • 1
Demitri
  • 21
  • 1
1

Using some of the following events you can work out which direction a swipe has been made

  • touchstart: Occurs when a finger is placed on the screen
  • touchend: Occurs when a finger is removed from the screen
  • touchmove: Occurs when a finger already placed on the screen is moved across the screen
  • touchcancel: Occurs when a touch is cancelled before the finger is actually removed from the screen

Record the x,y position on touchstart and again on touchend and determine which direction a swipe has been made

Manse
  • 37,765
  • 10
  • 83
  • 108