Created
June 18, 2013 12:13
-
-
Save amuntasim/5804857 to your computer and use it in GitHub Desktop.
simple progress bar using jquery and css only
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 http-equiv="Content-type" content="text/html; charset=utf-8"> | |
<title>demo</title> | |
<script src="http://code.jquery.com/jquery-1.10.0.min.js"> </script> | |
<style type="text/css"> | |
#progressBar { | |
width: 400px; | |
height: 22px; | |
border: 1px solid #111; | |
background-color: #292929; | |
} | |
#progressBar div { | |
height: 100%; | |
color: #fff; | |
text-align: right; | |
line-height: 22px; /* same as #progressBar height if we want text middle aligned */ | |
width: 0; | |
background-color: #0099ff; | |
} | |
</style> | |
</head> | |
<body id="demo" onload="" style="padding-top:30px"> | |
<div id="progressBar"> <div> | |
<script type="text/javascript" > | |
function progress(percent, $el) { | |
var progressBarWidth = percent * $el.width() / 100; | |
$el.find('div').animate({ width: progressBarWidth }, 500).html(percent + "% "); | |
} | |
var globalP = 0; | |
var startProgressBar = function(){ | |
if(globalP < 100){ | |
globalP = globalP + 1; | |
progress(globalP, $('#progressBar')); | |
setTimeout(startProgressBar, 500); | |
} | |
else { | |
//done | |
} | |
} | |
$(document).ready(function(){ | |
startProgressBar(); | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment