One of the great features of HTML5 is the <progress>
element. The <progress> element represents the progress of a
task, you can use it to display an upload progress per example. To create a
dinamic progress bar, we need to combine HTML5 with some JavaScript:
<!DOCTYPE html>
<html>
<head>
<script
type="text/javascript">
function
startProgress() {
var
progressBar = document.getElementById("progressBar"),
loaded =
0;
function
load() {
loaded
+= 5;
progressBar.value = loaded;
document.getElementById("progress").innerHTML =
"Progress: " + loaded + " %";
if(loaded == 100) {
clearInterval(interval);
document.getElementById("progress").innerHTML = "Complete
!";
}
};
var
interval = setInterval(function(){load();}, 1000);
}
</script>
</head>
<body>
<progress
id="progressBar" value="0" max="100">
The
progress element is currently supported in Firefox, Opera, and Chrome.
</progress>
<p
id="progress"></p>
<button
type="button" onclick="startProgress()">Start
progress</button>
</body>
</html>
And the output will be:
The <
progress > tag is
currently supported in Firefox,
Opera and Chrome.
value="0" – specifies how much of the task has been completed
max="100" – specifies how much work the task requires in total