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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -