Added swipe-mobule

This commit is contained in:
Tobias Reich 2014-03-26 23:02:45 +01:00
parent faba762f98
commit 9a18939090
3 changed files with 76 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -109,6 +109,18 @@ $(document).ready(function(){
});
}
$(document)
.on("touchstart", "#imageview", function(e) {
swipe.start("#image", e);
})
.on("touchmove", function(e) {
console.log('move');
swipe.move(e);
})
.on("touchend", "#imageview", function() {
swipe.stop();
});
/* Document */
$(document)

61
assets/js/swipe.js Normal file
View File

@ -0,0 +1,61 @@
/**
* @name Swipe Module
* @description Swipes and moves an object.
* @author Tobias Reich
* @copyright 2014 by Tobias Reich
*/
swipe = {
object: null,
position: {
x: null,
y: null
},
start: function(object, e) {
console.log('start with ' + object);
swipe.object = object;
if (swipe.position.x===null)
swipe.position.x = e.originalEvent.pageX;
if (swipe.position.y===null)
swipe.position.y = e.originalEvent.pageY;
return true;
},
move: function(e) {
var offset = {
x: -1 * (swipe.position.x - e.originalEvent.pageX),
y: -1 * (swipe.position.y - e.originalEvent.pageY)
}
if (swipe.position.x!==null) {
$(swipe.object).css({
'-webkit-transform': 'translateX(' + offset.x + 'px);',
'-moz-transform': 'translateX(' + offset.x + 'px);',
'transform': 'translateX(' + offset.x + 'px);'
});
}
console.log(offset);
},
stop: function() {
console.log('stop');
swipe.object = null;
swipe.position.x = null;
swipe.position.y = null;
}
};