DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   Preventing the delay when src attribute of the images set via javascript (http://www.daniweb.com/forums/thread113344.html)

serkansendur Mar 11th, 2008 12:34 pm
Preventing the delay when src attribute of the images set via javascript
 
When you assign a source to an image via javascript, it will take sometime to load the image. To get around this problem you can preload the images creating virtual images via javascript as follows :

if(document.images)
{
// create a virtual image
var img1 = new Image();
// preload the source
img1.src = "images/masterpage/menu_1_hover.jpg";
var img2 = new Image();
img2.src = "images/masterpage/menu_1.jpg";
}


All times are GMT -4. The time now is 1:46 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC