Created
January 23, 2014 20:27
-
-
Save Nilpo/8586142 to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="An example of simple JavaScript animation for HTML5 meters and progress bars." /> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<p><meter id="meter" value="300" min="0" max="500">300Gb of 500Gb</meter></p> | |
<p><progress id="progress" value="50" max="100">50%</progress></p> | |
</body> | |
</html> |
This file contains 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
/** | |
* A simple function to animate HTML5 meters | |
* and progress bars. | |
*/ | |
animateProgress = function(el, start, stop, interval, reverse) { | |
interval = interval || 10; | |
stop = stop || el.max; | |
if (reverse) stop = el.min; | |
if (start===undefined) el.value; // allow 0 value | |
var value = start; | |
var id = setInterval(function() { | |
if (start<stop) value++; | |
if (start>stop) value--; | |
el.value = value; | |
if (value == stop) clearInterval(id); | |
}, interval); | |
}; | |
loadProgress = function(el, interval) { | |
animateProgress(el, 0, el.value, interval, false); | |
}; | |
var meter = document.getElementById("meter"); | |
animateProgress(meter, 0, 500, 5); | |
var progress = document.getElementById("progress"); | |
loadProgress(progress, 40); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment