tweetypie
08-03-2006, 10:00 AM
Can somebody help me out?
My problem is with an image swap with a caption. no wait!...
The caption is already on the page, while the pictures are back on the server. what i want is for both to display at the same moment: only switch the caption when the image is loaded.
The page is at www.geocities.com/grintches/thea.html , although you may have to beat back the adverts in order to see it.
here's my code. professionals shut your eyes now:
imagea=new Image(); imageb=new Image() etc......
// make empty image objects
var list= new Array("this.jpg","that.jpg... etc
// a list of the image sources
function writeit(text,d,pic,imageobj,f) {
if(!imageobj.src) {
thediv[d].innerHTML='collecting picture...';
imageobj.src=list[f]; }
theimg[pic].src=imageobj.src
thediv[d].innerHTML=text
}
for instance it's called like this: onclick="writeit('the caption',2,3,imagea,4)".
It's going to write 'text' into a div called 'd', make list[f] the src for one of the empty image objects, and then swap imageobj.src into <img id=pic....
so: if imageobj.src is false, it goes to fetch the missing image and give imagevar a src. Before it goes off it writes up 'collecting picture...' - to tell the viewer that something's going on. And it's not supposed to change that til it's got the new image ready..
anyway, it doesn't work: it switches the caption straight away. I thought a computer did only one thing at a time, and would pause the function while fetching the image file... obviously not.
i tried: while(!imagevar.complete){ twiddle thumbs } but this makes the page freeze - in this case it does fully concentrate on doing what's in the brackets.....
what do i do??? i feel stupid. many many thanks if you can answer
My problem is with an image swap with a caption. no wait!...
The caption is already on the page, while the pictures are back on the server. what i want is for both to display at the same moment: only switch the caption when the image is loaded.
The page is at www.geocities.com/grintches/thea.html , although you may have to beat back the adverts in order to see it.
here's my code. professionals shut your eyes now:
imagea=new Image(); imageb=new Image() etc......
// make empty image objects
var list= new Array("this.jpg","that.jpg... etc
// a list of the image sources
function writeit(text,d,pic,imageobj,f) {
if(!imageobj.src) {
thediv[d].innerHTML='collecting picture...';
imageobj.src=list[f]; }
theimg[pic].src=imageobj.src
thediv[d].innerHTML=text
}
for instance it's called like this: onclick="writeit('the caption',2,3,imagea,4)".
It's going to write 'text' into a div called 'd', make list[f] the src for one of the empty image objects, and then swap imageobj.src into <img id=pic....
so: if imageobj.src is false, it goes to fetch the missing image and give imagevar a src. Before it goes off it writes up 'collecting picture...' - to tell the viewer that something's going on. And it's not supposed to change that til it's got the new image ready..
anyway, it doesn't work: it switches the caption straight away. I thought a computer did only one thing at a time, and would pause the function while fetching the image file... obviously not.
i tried: while(!imagevar.complete){ twiddle thumbs } but this makes the page freeze - in this case it does fully concentrate on doing what's in the brackets.....
what do i do??? i feel stupid. many many thanks if you can answer