Last active
August 29, 2015 14:04
-
-
Save davidchase/d59e6d42c378da843ce7 to your computer and use it in GitHub Desktop.
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
| // Orginal forked from | |
| // https://gist.github.com/localpcguy/1373518 | |
| 'use strict'; | |
| var Swiper = { | |
| config: { | |
| "touchstart": { | |
| "x": -1, | |
| "y": -1 | |
| }, | |
| "touchmove": { | |
| "x": -1, | |
| "y": -1 | |
| }, | |
| "touchend": false, | |
| "direction": "" | |
| }, | |
| touchHandler: function(event) { | |
| var touch; | |
| event.preventDefault(); | |
| if (typeof event.touches !== 'undefined') { | |
| touch = event.changedTouches[0]; | |
| var gestures = { | |
| 'touchstart': function(event) { | |
| Swiper.config[event.type].x = touch.pageX; | |
| Swiper.config[event.type].y = touch.pageY; | |
| }, | |
| 'touchmove': function(event) { | |
| Swiper.config[event.type].x = touch.pageX; | |
| Swiper.config[event.type].y = touch.pageY; | |
| }, | |
| 'touchend': function(event) { | |
| Swiper.config[event.type] = true; | |
| if (Swiper.config.touchstart.x > -1 && Swiper.config.touchmove.x > -1) { | |
| Swiper.config.direction = Swiper.config.touchstart.x < Swiper.config.touchmove.x ? "right" : "left"; | |
| console.log(Swiper.config.direction); | |
| } | |
| } | |
| }; | |
| if (gestures && typeof(gestures[event.type]) === 'function') { | |
| gestures[event.type].call(this, event); | |
| } | |
| } | |
| }, | |
| init: function() { | |
| document.addEventListener('touchstart', Swiper.touchHandler, false); | |
| document.addEventListener('touchmove', Swiper.touchHandler, false); | |
| document.addEventListener('touchend', Swiper.touchHandler, false); | |
| } | |
| }; | |
| Swiper.init(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
slightly improved from the fork as well as bugs fixed... more on this later