Skip to content

Instantly share code, notes, and snippets.

@shulard
Created June 10, 2015 14:04
Show Gist options
  • Save shulard/5efab6c7988cd8e54f24 to your computer and use it in GitHub Desktop.
Save shulard/5efab6c7988cd8e54f24 to your computer and use it in GitHub Desktop.
Just a swipe detection in javascript
var $el = $('... selector');
$el.bind({
touchstart: function(event) {
$el.data('start.x',event.originalEvent.touches[0].pageX);
},
touchmove: function(event) {
$el.data('delta', event.originalEvent.touches[0].pageX - $el.data('start.x'));
},
touchend: function(event) {
if( Math.abs($el.data('delta')) > 100 ) {
//Here the user swipe for 100px left or right...
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment