Skip to content

Instantly share code, notes, and snippets.

@Gautier
Created March 16, 2010 00:13
Show Gist options
  • Save Gautier/333492 to your computer and use it in GitHub Desktop.
Save Gautier/333492 to your computer and use it in GitHub Desktop.
Javascript pendulum CSS3
/**
* 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