Created
June 10, 2015 14:04
-
-
Save shulard/5efab6c7988cd8e54f24 to your computer and use it in GitHub Desktop.
Just a swipe detection in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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