Last active
October 5, 2016 15:05
-
-
Save tingwei628/0a03a87c32de4b06882927a605256f86 to your computer and use it in GitHub Desktop.
website progress bar
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() { | |
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || | |
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; | |
window.requestAnimationFrame = requestAnimationFrame; | |
})(); | |
var start = null; | |
var d = document.getElementById("SomeElementYouWantToAnimate"); | |
d.style.backgroundColor = 'red'; | |
d.style.color = 'red'; | |
d.style.height = '5px'; | |
function step(timestamp) { | |
var progress; | |
if (start === null) start = timestamp; | |
progress = timestamp - start; | |
d.style.width = Math.min(progress/10, 100) + "%"; | |
if (progress < 1000) { | |
window.requestAnimationFrame(step); | |
} else { | |
d.style.opacity = 0; | |
} | |
} | |
window.requestAnimationFrame(step); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forget to add this in HTML