Created
March 16, 2010 00:13
-
-
Save Gautier/333492 to your computer and use it in GitHub Desktop.
Javascript pendulum CSS3
This file contains 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
/** | |
* Oh yeah | |
*/ | |
function rotate(id) { | |
var element = document.getElementById(id); | |
function applyRotate(angle) { | |
var strAngle = "rotate(" + angle + "rad)"; | |
element.style.WebkitTransform = strAngle; | |
element.style.MozTransform = strAngle; | |
} | |
function update() { | |
var start = new Date().getTime(); | |
update.acceleration = update.g * update.angle; | |
update.speed += update.acceleration; | |
update.angle += update.speed; | |
applyRotate(update.angle); | |
var elapsed = new Date().getTime() - start; | |
setTimeout(update, 80-elapsed); | |
} | |
update.g = -.005; | |
update.acceleration = 1; | |
update.speed = 0; | |
update.angle = .1; | |
element.style.WebkitTransformOrigin = "center top"; | |
element.style.MozTransformOrigin = "center top"; | |
update(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment