i just wrote 2 function usable for a preloader
a function to set the percent of a bar and a function to get it.
i thought someone might find any use in them
preloader html (stole a image from pd as background of preloader)
HTML Code:
<div style="width:150px;"><div style="text-align:center;">Loading... <span id="percent">0</span>%</div> <center><img id="bar" src="http://img443.imageshack.us/img443/3213/pdbackup1fh6.jpg" style="display:none;height:15;"></center></div>
functions Code:
<script>
function getPercent(){
if(document.getElementById("bar").style.display=='none'){
p=0
}else{
p=parseInt(document.getElementById("bar").style.width)
}
return p
}
function setPercent(to){
if(to==0){
document.getElementById("bar").style.display='none'
}else{
document.getElementById("bar").style.display='block'
document.getElementById("bar").style.width=to+'%'
}
document.getElementById("percent").innerHTML=getPercent()
}
</script> the functions should be used like this:
to get how much percent it currently is: Code:
var currentpercent = getPercent()
to change the current percent to 50%: also to test the functions i wrote a small code to use the functions to make the percent increase and decrease, about 10% per second up and down, once it reaches 100% is will start decreasing after 2 and a half sec, than once it reaches 0% it will increase again after 2 and a half sec
Code:
<script>
function increase(){
if(getPercent()<100){
setPercent(getPercent()+1)
}else{
clearInterval(inc)
setTimeout('inc=setInterval("decrease()",100)',2500)
}}
function decrease(){
if(getPercent()>0){
setPercent(getPercent()-1)
}else{
clearInterval(inc)
setTimeout('inc=setInterval("increase()",100)',2500)
}}
inc=setInterval("increase()",100)
</script> preview:
Ripway.com - fast, free file hosting and website hosting