lychee/assets/js/swipe.js

54 lines
945 B
JavaScript
Raw Normal View History

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
if (obj) swipe.obj = obj;
if (tolerance) swipe.tolerance = tolerance;
2014-03-26 22:02:45 +00:00
return true;
},
move: function(e) {
if (swipe.obj===null) return false;
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) {
if (e.x<=-swipe.tolerance) left(true);
else if (e.x>=swipe.tolerance) right(true);
2014-04-01 20:42:12 +00:00
else if (swipe.obj!==null) {
2014-03-26 22:36:50 +00:00
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
}
};