2014-03-26 22:02:45 +00:00
|
|
|
/**
|
|
|
|
* @name Swipe Module
|
|
|
|
* @description Swipes and moves an object.
|
|
|
|
* @author Tobias Reich
|
|
|
|
* @copyright 2014 by Tobias Reich
|
|
|
|
*/
|
|
|
|
|
|
|
|
swipe = {
|
|
|
|
|
2014-03-26 22:36:50 +00:00
|
|
|
obj: null,
|
|
|
|
tolerance: 150,
|
2014-03-26 22:52:25 +00:00
|
|
|
offset: 0,
|
2014-03-26 22:02:45 +00:00
|
|
|
|
2014-03-26 22:36:50 +00:00
|
|
|
start: function(obj, tolerance) {
|
2014-03-26 22:02:45 +00:00
|
|
|
|
2014-03-26 22:36:50 +00:00
|
|
|
console.log('start with ' + obj);
|
2014-03-26 22:02:45 +00:00
|
|
|
|
2014-03-26 22:36:50 +00:00
|
|
|
if (obj) swipe.obj = obj;
|
|
|
|
if (tolerance) swipe.tolerance = tolerance;
|
2014-03-26 22:02:45 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
move: function(e) {
|
|
|
|
|
2014-03-26 22:36:50 +00:00
|
|
|
console.log(e);
|
2014-03-26 22:02:45 +00:00
|
|
|
|
2014-03-26 22:54:19 +00:00
|
|
|
swipe.offset = -1 * e.x;
|
2014-03-26 22:02:45 +00:00
|
|
|
|
2014-03-26 22:36:50 +00:00
|
|
|
swipe.obj.css({
|
2014-03-26 22:56:22 +00:00
|
|
|
WebkitTransform: 'translateX(' + swipe.offset + 'px)',
|
|
|
|
MozTransform: 'translateX(' + swipe.offset + 'px)',
|
|
|
|
transform: 'translateX(' + swipe.offset + 'px)'
|
2014-03-26 22:36:50 +00:00
|
|
|
});
|
2014-03-26 22:02:45 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-03-26 22:36:50 +00:00
|
|
|
stop: function(e, left, right) {
|
|
|
|
|
|
|
|
console.log('stop with ' + e.x);
|
2014-03-26 22:02:45 +00:00
|
|
|
|
2014-03-26 22:54:19 +00:00
|
|
|
if (e.x<=-swipe.tolerance) left();
|
|
|
|
else if (e.x>=swipe.tolerance) right();
|
2014-03-26 22:36:50 +00:00
|
|
|
else {
|
|
|
|
console.log('reset');
|
|
|
|
swipe.obj.css({
|
|
|
|
WebkitTransform: 'translateX(0px)',
|
|
|
|
MozTransform: 'translateX(0px)',
|
|
|
|
transform: 'translateX(0px)'
|
|
|
|
});
|
|
|
|
}
|
2014-03-26 22:02:45 +00:00
|
|
|
|
2014-03-26 22:36:50 +00:00
|
|
|
swipe.obj = null;
|
2014-03-26 22:52:25 +00:00
|
|
|
swipe.offset = 0;
|
2014-03-26 22:02:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|