Domain Discussion Board

Go Back   Domain Discussion Board > Web Hosting & Web Design > Scripts

 
Reply
 
LinkBack Thread Tools Display Modes
Javascript preloader functions
Old
  (#1 (permalink))
godkillah
Junior Member
godkillah is on a distinguished road
 
Status: Offline
Posts: 25
Points: 50.5
Bank: 0.0
Total Points: 50.5
Donate
Join Date: Sep 2007
Rep Power: 0
Javascript preloader functions - 07-13-2008, 01:12 PM

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%:
Code:
setPercent(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
   
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 0.1
Points Per Thread: 15.0
Points Per Reply: 5.0


Similar Threads
Thread Thread Starter Forum Replies Last Post
All Programming Tutorials - Online For Ye All! hariharan Wonderful Websites 17 04-29-2007 05:22 AM


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 ©2007, Crawlability, Inc.