html - Image preload jquery -
i'm looking best way preload images jquery.
i tried using code doesn't seem work:
function preload(arrayofimages) { $(arrayofimages).each(function(){ $('<img/>')[0].src = this; // alternatively use: // (new image()).src = this; }); } // usage: preload([ 'img/preload.jpg' ]);
this markup:
<div class="item"> <img src="img/lookbook_item1.jpg" alt="lookbook_item1" width="187" height="259"> </div> <div class="item"> <img src="img/lookbook_item1.jpg" alt="lookbook_item1" width="187" height="259"> </div> <div class="item"> <img src="img/lookbook_item2.jpg" alt="lookbook_item2" width="383" height="259"> </div>
i don't want use plugins, small script can fadein or similar.
try way:
$.each( arrayofimages, function( i, src ) { var img = new image() img.src = src; img.load = function() { $("img[src=" + src + "]").fadein(); }; });
Comments
Post a Comment