Preloading multiple images using single function

by Nirmala 2009-05-20 16:59:32

Hi...
In our webpage having more images means that takes lot of times to load all images. To overcome this issue use the below code.

<script type="text/javascript>
function preload()
{
var args=preload.arguments;
document.imageArray=new Array(args.length);
for(var i=0;i<args.length;i++)
{
document.imageArray[i]=new Image;
document.imageArray[i].src=args[i];
}
}
</script>

Call the preload() function.

<body onload="preload('img1.gif','img2.gif',...)">

Tagged in:

1785
like
2
dislike
0
mail
flag

You must LOGIN to add comments