Created
February 2, 2012 14:34
-
-
Save atleastimtrying/1723736 to your computer and use it in GitHub Desktop.
swipey js
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
window.onload = function(){ | |
var display = document.getElementsByTagName("body"); //could be any element | |
var touched = false; // a useful flag for restructing otehr actions | |
var increment = 0; // the amount we increment | |
var addRotateTouches = function(){ | |
display.addEventListener("touchstart", rotateStart ,false); | |
display.addEventListener("touchmove", rotateMove ,false); | |
display.addEventListener("touchend", rotateEnd ,false); | |
} | |
var removeRotateTouches = function(){ | |
display.removeEventListener("touchstart", rotateStart ,false); | |
display.removeEventListener("touchmove", rotateMove ,false); | |
display.removeEventListener("touchend", rotateEnd ,false); | |
} | |
var rotateStart = function(){ | |
touched = true; | |
startX = window.Touch ? event.touches[0].pageX : event.pageX; | |
event.preventDefault(); | |
} | |
var rotateMove = function(event){ | |
var velocityLimit = window.Touch ? 20 : 10; | |
event.preventDefault(); | |
var newX = (window.Touch ? event.touches[0].pageX : event.pageX); | |
var curX = newX - startX; | |
if (curX > velocityLimit || curX < -velocityLimit) { | |
var delta = parseInt(curX / velocityLimit); | |
startX = newX; | |
increment += delta; | |
increment = (((increment % 36) + 36) % 36);// a modulus fix. | |
console.log(increment); | |
} | |
} | |
var rotateEnd = function(){ | |
touched = false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment