Skip to content

Instantly share code, notes, and snippets.

@tingwei628
Last active October 5, 2016 15:05
Show Gist options
  • Save tingwei628/0a03a87c32de4b06882927a605256f86 to your computer and use it in GitHub Desktop.
Save tingwei628/0a03a87c32de4b06882927a605256f86 to your computer and use it in GitHub Desktop.
website progress bar
(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);
@tingwei628
Copy link
Author

Don't forget to add this in HTML

 <div id="SomeElementYouWantToAnimate"></div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment