| View previous topic :: View next topic |
| Author |
Message |
ranosb
Joined: 15 Apr 2008 Posts: 14
|
Posted: Fri Apr 18, 2008 7:01 pm Post subject: Preload images |
|
|
Is there not a better preload script, this does nothing. My page sometimes shows the images, sometimes not.
Where do I call this function?
function preloadit() {
myimg1 = new Image(32,32);
myimg2 = new Image(32,32);
myimg1.src = “32x32.ico”;
myimg2.src = “checkbox.png”;
}
preloadit() |
|
| Back to top |
|
 |
|
|
webmaster Site Admin

Joined: 17 Aug 2004 Posts: 3614 Location: Sweden
|
Posted: Sat Apr 19, 2008 12:20 am Post subject: Re: Preload images |
|
|
You can easily do it with CSS just like this:
| Code: |
<img src="image1.jpg" alt="" style="display:none;" />
<img src="image2.jpg" alt="" style="display:none;" />
<img src="image3.jpg" alt="" style="display:none;" /> |
|
|
| Back to top |
|
 |
rangana 500+ Club

Joined: 27 Feb 2008 Posts: 546 Location: Cebu City Philippines
|
Posted: Sat Apr 19, 2008 12:43 am Post subject: Re: Preload images |
|
|
Call that function during onload
...And as what webmaster says, CSS can do it for you...inline display:none; would'nt be ideal if you had a number of images...give each image a class, then use display:none; in your CSS declaration
...Then decide as to when you want the image be displayed...do get back if you're still stumped  |
|
| Back to top |
|
 |
ranosb
Joined: 15 Apr 2008 Posts: 14
|
Posted: Sat Apr 19, 2008 4:35 am Post subject: Re: Preload images |
|
|
| rangana wrote: |
Call that function during onload
|
Thats all it needed..
TY |
|
| Back to top |
|
 |
rangana 500+ Club

Joined: 27 Feb 2008 Posts: 546 Location: Cebu City Philippines
|
Posted: Sat Apr 19, 2008 4:52 am Post subject: Re: Preload images |
|
|
Yes....if you want it to work during onload...or you could always trigger the function depending on what you want,,,,either through mouseover, focus,blur...click...and a lot more...
...For the onload, you can also do it solely in the JS:
| Code: |
window.onload = function()
{
myimg1 = new Image(32,32);
myimg2 = new Image(32,32);
myimg1.src = “32x32.ico”;
myimg2.src = “checkbox.png”;
}
|
|
|
| Back to top |
|
 |
|