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

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -