privateer
04-09-2003, 09:58 AM
Having preloaded an image, does anyone know how to use the preloaded image to replace the background image of a span?
Specifically:
1. A <span> has a background of: a.gif
2. b.gif has been preloaded into js object: imgB (holds b.gif
and the path to b.gif is images/b.gif)
3. Now we need to replace the background of the <span> with imgB without causing the browser to simply reload it from the server (say on a mouse over event).
The code fragment:
<spanid>.style.backgroundImage = "url(images/b.gif)";
will load it from the server.
<spanid>.style.backgroundImage = "url(" + imgB.src + ")";
will also load the image
However, since the style backgroundImage attribute does not accept an image object as an argument and you must pass it the URL from the source attribute of the image object;
Is the preloaded image used or is the image simply requested again from the server?
Thanks
Specifically:
1. A <span> has a background of: a.gif
2. b.gif has been preloaded into js object: imgB (holds b.gif
and the path to b.gif is images/b.gif)
3. Now we need to replace the background of the <span> with imgB without causing the browser to simply reload it from the server (say on a mouse over event).
The code fragment:
<spanid>.style.backgroundImage = "url(images/b.gif)";
will load it from the server.
<spanid>.style.backgroundImage = "url(" + imgB.src + ")";
will also load the image
However, since the style backgroundImage attribute does not accept an image object as an argument and you must pass it the URL from the source attribute of the image object;
Is the preloaded image used or is the image simply requested again from the server?
Thanks