Skip to content

Instantly share code, notes, and snippets.

@davidchase
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save davidchase/d59e6d42c378da843ce7 to your computer and use it in GitHub Desktop.

Select an option

Save davidchase/d59e6d42c378da843ce7 to your computer and use it in GitHub Desktop.
// 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();
@davidchase
Copy link
Author

slightly improved from the fork as well as bugs fixed... more on this later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment