jquery - Showing loading gif only till certain amount of images are loaded -


i have site fullscreen background carousel , loading gif on window load. problem depending on site, have 10 40 images in carousel, means loading gif spinning way long time.

i'm thinking idea display loading gif till first 5 images loaded. that, plus 10 seconds every image shown, gives enough time other images load.

the problem don't know how approach solution. thoughts?

here's jquery:

<script type="text/javascript">   var image = new image();   image.src = 'img/loading.gif'; //<![cdata[   $(window).load(function() { // makes sure whole site loaded     $('#status').fadeout(); // first fade out loading animation     $('#preloader').delay(350).fadeout('slow', function(){       $( "#carousel-example-generic" ).attr('data-ride', "carousel");     }); // fade out white div covers website.     $('body').delay(350).css({'overflow':'visible'});   }); //]]> </script>  

and piece of html:

<div id="carousel-example-generic" class="carousel slide" data-ride="0">  <div class="carousel-inner">  <div class="item active">     <img src="./img/1.jpg" alt="" />     <div class="container">       <div class="carousel-caption">       </div>     </div>   </div>   <div class="item">     <img src="./img/2.jpg" alt="" />     <div class="container">       <div class="carousel-caption">       </div>     </div>   </div>   <div class="item">     <img src="./img/3.jpg" alt="" />     <div class="container">       <div class="carousel-caption">       </div>     </div>   </div>   <div class="item">     <img src="./img/4.jpg" alt="" />     <div class="container">       <div class="carousel-caption">       </div>     </div>   </div>   <div class="item">     <img src="./img/5.jpg" alt="" />     <div class="container">       <div class="carousel-caption">       </div>     </div>   </div>   <div class="item">     <img src="./img/6.jpg" alt="" />     <div class="container">       <div class="carousel-caption">       </div>     </div>   </div>   <div class="item">     <img src="./img/7.jpg" alt="" />     <div class="container">       <div class="carousel-caption">       </div>     </div>   </div>   <div class="item">     <img src="./img/8.jpg" alt="" />     <div class="container">       <div class="carousel-caption">       </div>     </div>   </div>   <div class="item">     <img src="./img/9.jpg" alt="" />     <div class="container">       <div class="carousel-caption">       </div>     </div>   </div>   <div class="item">     <img src="./img/10.jpg" alt="" />     <div class="container">       <div class="carousel-caption">       </div>     </div>   </div> </div> 

found nice , easy way!

<script>   var numimagesloaded = 0; function incrementandcheckloading(){     numimagesloaded++;     if(numimagesloaded == 3){         //kill loading screen, launch carousel     } }      image1 = new image(); image1.src = "img/1.jpg" image1.onload = incrementandcheckloading; image2 = new image(); image2.src = "img/2.jpg" image2.onload = incrementandcheckloading; image3 = new image(); image3.src = "img/3.jpg" image3.onload = incrementandcheckloading; </script> 

with script, loading screen disappear when firsts 3 images loaded, , because each image displays during x amount of seconds, site has time load other images on back.

thanks dtech, found here.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -