I’m trying to implement linear carousel with js and HTML5.
The problem that I need to calculate the offset (dx) from the current touch in the screen.
my code:
document.addEventListener('touchmove', function(event) {
event.preventDefault();
var touch = event.touches[0];
posx=touch.pageX;
posy=touch.pageY;
},false);
For Example: current posx is 365 and i moved 1px right. then my dx will be 1 and so on…
Thanks in advance.
Save the current x and y position to global variables on every change and calculate the difference between the last and current values before overwriting the values again.