View Full Version : Text preloader....plz help
shivboy
02-16-2003, 10:57 PM
Hi,
i want to load text into a layer dynamically. But i want to make a preloader that shows the % loading of the text. Can anybody please give me some idea as to how to go about it? Any help is appreciated.
Thanx,
Shivboy
Graeme Hackston
02-17-2003, 02:47 AM
I haven't tried this but I've been thinking it might work.
See my response here
http://www.codingforums.com/showthread.php?s=&threadid=14018
Now, for example you have 100 bytes total of text to load. Put a transparent gif in the text at 25 byte intervals then increment your bar when each image load is complete. The array would be an array of your transparent gifs (rather than document.images). Increment the bar inside the loop.
I've been wondering about this, let me know if you get it to work
Graeme Hackston
02-18-2003, 02:24 AM
Just rethinking my suggestion. How about just dumping function calls at intervals in the text. I know tables atleast load progressively. Something like this
function Show_Progress(amount) {
document.getElementById('whatever').innerHTML = 25 * amount + '%'
}
then in the text
text text text
Show_Progress(1)
text text text
Show_Progress(2)
text text text
Show_Progress(3)
text text text
Show_Progress(4)
shivboy
02-18-2003, 09:20 PM
hi Graeme
thanx for replying man. i got the idea that u suggested. but i wanna ask u that where do u intend to store the text? what i could figure out was, that, u intend to store it as a string in a variable. if u intend to do that, then i wud suggest that y not put a character, say, * or $ in the string at regular intervals. then using split(), u load the text and simultaneously increase the width of the progress bar. what do u think?
shivboy
Graeme Hackston
02-19-2003, 12:28 AM
Cool, I'm leary of reg express meta-characters in a string, see here
http://www.codingforums.com/showthread.php?s=&threadid=14216
They'll probably work fine, I'm just gun shy and used <br> below :o
split() is a great idea. This looks like it "might" work but my CPU is set up for images and to fast to test offline. I set it up for an onload condition that you don't need just to see if it could work. You can put it in a function. What I don't know is if the loop will wait for the text to load in each cycle. It might just instantly count to 100. Give it a try and let me know how it goes.
<html>
<head>
<title></title>
</head>
<body>
<div id="show">
</div>
<div id="dump">
</div>
<script>
str = 'blah<br>blah<br>blah<br>blah<br>blah<br>blah'
strs = str.split('<br>')
strs_length = strs.length
for (var i=0;i<strs_length;i++) {
document.getElementById('dump').innerHTML += strs[i]
document.getElementById('show').innerHTML = Math.round(100/ strs_length * (i + 1))
alert(i)
}
</script>
</body>
</html>
Graeme Hackston
02-19-2003, 12:55 AM
I just noticed I had 1 too many <br>s in the string above and fixed it. If this doesn't work It still might be doable with gifs.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.