[Javascript] Calling images only when needed.

Peter-Paul Koch pp.koch at gmail.com
Mon Feb 14 16:33:16 CST 2005


> >> If you use CSS to apply {display: none;} to an image (or an image's
> >> container) it will not download until you change this to {display:
> >> block;} or {display: inline;}.
> >
> > Unfortunately that is true only in Opera and Safari. Explorer (Win and
> > Mac) and Mozilla immediately download the images.
> >
> 
> That's why I need something else to control how the images are displayed and
> when.
> Why should a dial up user suffer and wait while the images are being
> downloaded never to be seen by the visitor? And take up space on his
> machine.
> I'm looking at the high probability of doing an array for each selection,
> then load the images when they're called on.
> At least that way the user wouldn't be waiting so long.

Create the IMG elements as needed:

var x = document.createElement('img');
x.src = 'path/to/image.jpg';
document.someNode.appendChild(x);

-- 
-------------------------------------------------------------------
ppk, freelance web developer

Recent article: JavaScript triggers, 
http://www.alistapart.com/articles/scripttriggers/

Bug Report: Report bugs yourself, or comment on previously 
reported ones.
http://www.quirksmode.org/bugreports/
------------------------------------------------------------------



More information about the Javascript mailing list