i\'m trying to implement a touch listener for tablets to trigger some actions depending whether it touchmoved upwards or downwards.
I tried the native listener:
This solution takes into account change in directions which the current answers does not. The solution below also takes care of touch sensitivity; this when the user is moving in one direction but on touch end the users finger nudges in a different direction messing up the actual direction.
var y = 0; //current y pos
var sy = y; //previous y pos
var error = 5; //touch sensitivity, I found between 4 and 7 to be good values.
function move(e) {
//get current y pos
y = e.pageY;
//ingnore user jitter
if (Math.abs(y - sy) > error) {
//find direction of y
if (y > sy) {
//move down
} else {
//move up
}
//store current y pos
sy = y;
}
}