Created
January 15, 2014 15:50
-
-
Save opi/8438657 to your computer and use it in GitHub Desktop.
touch event js
This file contains hidden or 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
| /** | |
| * 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