Skip to content

Instantly share code, notes, and snippets.

@RitaDias
Created January 16, 2017 14:27
Show Gist options
  • Save RitaDias/2044319de1ce8297d9ddee732466a6a4 to your computer and use it in GitHub Desktop.
Save RitaDias/2044319de1ce8297d9ddee732466a6a4 to your computer and use it in GitHub Desktop.
function onTouchStart(evt) {
startTime = new Date().getTime();
startX = evt.touches[0].pageX;
startY = evt.touches[0].pageY;
touchingElement = true;
touchStart(startX, startY);
}
function onTouchMove(evt) {
if (!touchingElement)
return;
currentX = evt.touches[0].pageX;
currentY = evt.touches[0].pageY;
const translateX = currentX - startX; // distance moved in the x axis
const translateY = currentY - startY; // distance moved in the y axis
touchMove(evt, currentX, currentY, translateX, translateY);
}
function onTouchEnd(evt) {
if (!touchingElement)
return;
touchingElement = false;
const translateX = currentX - startX; // distance moved in the x axis
const translateY = currentY - startY; // distance moved in the y axis
const timeTaken = (new Date().getTime() - startTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment