Jump to content

preLoadImage


quangthang2004

Recommended Posts

Dear All, While I was surfing the internet, I got one snippet code about pre-loading images. Here is the code =====================================jQuery.preloadImages = function () { for (var i = 0; i ").attr(" src ", arguments); } }; // Usage $.preloadImages(" image1.gif ", " / path / to / image2.png ", " some / image3.jpg===================================== If someone understand above code, Please explain to me. I will appreciate your comment

Link to comment
Share on other sites

Here's a way to preload images by using the images to make a roll over effect.

<!doctype html><html><head><title>Preload Images/Roll Over</title><script type="text/javascript">window.onload = function preLoadImg(){	pic = new Array();	pic[0] = new Image();	pic[0].src = "images/pic0.jpg";	pic[1] = new Image();	pic[1].src = "images/pic1.jpg";} function rollOver(){   document.pic.src = pic[1].src;   // you can also use document.getElementById("pic").src = pic[1].src; here as well, but I just use the name attribute to access the img.   // document.getElementById("pic").src = pic[1].src; } function rollOut(){  document.pic.src = pic[0].src;  // document.getElementById("pic").src = pic[0].src;} </script></head><body><a href="#" onmouseover="rollOver();" onmouseout="rollOut();"><img id="pic" name="pic" src="images/pic0.jpg" /></a> </body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...