quangthang2004 Posted February 14, 2012 Share Posted February 14, 2012 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 More sharing options...
justsomeguy Posted February 14, 2012 Share Posted February 14, 2012 That code isn't correct, either the original was wrong or something got screwed up in the copy and paste. Link to comment Share on other sites More sharing options...
Don E Posted February 15, 2012 Share Posted February 15, 2012 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 More sharing options...
quangthang2004 Posted February 20, 2012 Author Share Posted February 20, 2012 Thanks all Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.