Skip to content

Instantly share code, notes, and snippets.

@marklearst
Created May 11, 2012 18:21
Show Gist options
  • Save marklearst/2661492 to your computer and use it in GitHub Desktop.
Save marklearst/2661492 to your computer and use it in GitHub Desktop.
simple swipe example
$(document).on('touchstart', "document", function(event) {
var orig = event.originalEvent,
trackTouchX = orig.changedTouches[0].pageX,
trackTouchY = orig.changedTouches[0].pageY,
trackIt = orig.changedTouches[0].pageX,
thresholdX = 20,
thresholdY = 5
});
$(document).on('touchend', "document", function(event) {
var orig = event.originalEvent;
if(Math.abs(trackTouchY - orig.changedTouches[0].pageY) < thresholdY)
if (trackTouchX < orig.changedTouches[0].pageX - thresholdX) {
goPrevious();
} else if (trackTouchX > orig.changedTouches[0].pageX + thresholdX) {
goNext();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment