hy guys, i was searching for a javascript or somting to preload a image, an i found this, wich goes in the head of the page:
[syntax=javascript]
<SCRIPT language="JavaScript">
<!--
pic1= new Image(100,25);
pic1.src="img/bg1.png";
//-->
</SCRIPT>
[/syntax]
and this needs to go in the body part pf the page where the image is diplayed:
[syntax=javascript]
<SCRIPT language="JavaScript">
<!--
if (document.images)
{
pic1= new Image(100,25);
pic1.src="http://someplace.com/image1.gif";
}
//-->
</SCRIPT>
[/syntax]
but my image is in the css, in the body tag, so how can i change this so that it will work, or how sould i added to the css?
thanks.
preloading a image
Re: preloading a image
Just doing
[syntax=javascript]pic1= new Image(100,25);
pic1.src="img/bg1.png"; [/syntax]
should start downloading the image, so you can use it where ever as you would normally do.
to change a background image with javascript
[syntax=javascript]element.style.backgroundImage = 'file.png';[/syntax]
[syntax=javascript]pic1= new Image(100,25);
pic1.src="img/bg1.png"; [/syntax]
should start downloading the image, so you can use it where ever as you would normally do.
to change a background image with javascript
[syntax=javascript]element.style.backgroundImage = 'file.png';[/syntax]
Re: preloading a image
so just adding the head part of the code will solve my problem?
even for the bg imge that is caled with css?
thanks
even for the bg imge that is caled with css?
thanks
Re: preloading a image
ta2shop wrote:so just adding the head part of the code will solve my problem?
Well it will start the image downloading.