Skip to content

Instantly share code, notes, and snippets.

@ethyde
Created August 15, 2015 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethyde/e41399e6af2dbcf23e24 to your computer and use it in GitHub Desktop.
Save ethyde/e41399e6af2dbcf23e24 to your computer and use it in GitHub Desktop.
<div id="a">a</div>
function animate(object, property, start_value, end_value, time) {
var frame_rate = 0.06; // 60 FPS
var frame = 0;
var delta = (end_value - start_value) / time / frame_rate;
var handle = setInterval(function() {
frame++;
var value = start_value + delta * frame;
object.style[property] = value + "px";
if (value == end_value) {
clearInterval(handle);
}
}, 1 / frame_rate);
}
animate(document.getElementById("a"), "top", 0, 100, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment