Created
December 29, 2014 05:50
-
-
Save winsonwq/9bbbbc6247b72865384f to your computer and use it in GitHub Desktop.
demo: tranditional implementation of animation
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
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