Determine vertical direction of a touchmove Determine vertical direction of a touchmove jquery jquery

Determine vertical direction of a touchmove


I had some issues in Ipad and solved it with two events

var ts;$(document).bind('touchstart', function (e){   ts = e.originalEvent.touches[0].clientY;});$(document).bind('touchend', function (e){   var te = e.originalEvent.changedTouches[0].clientY;   if(ts > te+5){      slide_down();   }else if(ts < te-5){      slide_up();   }});


You need to save the last position of the touch, then compare it to the current one.
Rough example:

var lastY;$(document).bind('touchmove', function (e){     var currentY = e.originalEvent.touches[0].clientY;     if(currentY > lastY){         // moved down     }else if(currentY < lastY){         // moved up     }     lastY = currentY;});


Aureliano's answer seems to be really accurate, but somehow it didn't work for me, so giving him the credits I decided to improve his answer with the following:

var ts;$(document).bind('touchstart', function(e) {    ts = e.originalEvent.touches[0].clientY;});$(document).bind('touchmove', function(e) {    var te = e.originalEvent.changedTouches[0].clientY;    if (ts > te) {        console.log('down');    } else {        console.log('up');    }});

I simply changed the 'touchend' event for 'touchmove'