Skip to content

Instantly share code, notes, and snippets.

@winsonwq
Created December 29, 2014 05:50
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 winsonwq/9bbbbc6247b72865384f to your computer and use it in GitHub Desktop.
Save winsonwq/9bbbbc6247b72865384f to your computer and use it in GitHub Desktop.
demo: tranditional implementation of animation
function run(element, cssProperty, value, duration) {
var initalValue = parseFloat(window.getComputedStyle(element)[cssProperty]);
var start = new Date().getTime();
window.requestAnimationFrame(function step() {
var progress = new Date().getTime() - start;
var newValue = bounce(progress, initalValue, parseFloat(value) - initalValue, duration);
element.style[cssProperty] = newValue + 'px';
if (progress < duration) {
window.requestAnimationFrame(step);
} else {
element.style[cssProperty] = value + 'px';
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment