Skip to content

Instantly share code, notes, and snippets.

@opi
Created January 15, 2014 15:50
Show Gist options
  • Select an option

  • Save opi/8438657 to your computer and use it in GitHub Desktop.

Select an option

Save opi/8438657 to your computer and use it in GitHub Desktop.
touch event js
/**
* Touch events
*/
wrapper.touch = {}
wrapper.get(0).ontouchstart = function(e) {
// Store start position
wrapper.touch.x = e.touches[0].clientX;
};
wrapper.get(0).ontouchmove = function(e) {
// only deal with one finger
if (e.touches.length == 1 && !wrapper.is(":animated")) {
// Get delta
var deltaX = wrapper.touch.x - e.touches[0].clientX;
// Move foward
if (deltaX > 30) {
wrapper.moveToNext();
}
// Move backward
else if (deltaX < -30) {
wrapper.moveToPrev();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment