Hi!
I guess there's an easy fix for this but I really can't find it. I'm not really into javascript so bear with me
On the title page of my online game I use javascript to display screenshots.
I use an invisible fixed ("absolute") positioned div (display: none) as a target for the screenshots.
When a user clicks on a thumbnail, I call a function called showScreenshot(image).
This function sets the background of the div to the appropriate screenshot, e.g.
I then set the opacity of the Div to 0, turn on the display and call a fade in function.Code:if(image=='admin') targetDiv.style.backgroundImage = "url(images/ss_administration.png)";
Works nicely. At least when your browser has cached the screenshots. Otherwise the empty div is displayed for a second or so until the image has loaded which occurs everytime you visit the page for the first time.Code:setOpacity(targetDiv,0); targetDiv.style.display = 'block'; fadeIn('screenshots-target', 0);
Is there a good way to make the fadeIn function wait until the image has loaded? (I guess "onload" is usable somehow? Maybe I should use an img tag inside the div instead of setting the background?
Of course I could always preload all fullsized screenshots, but I don't want to do that for every visit since not all visitors will look at them.
If you want to see the code in action, visit www.metropolisonline.org


LinkBack URL
About LinkBacks

Reply With Quote

