Jquery loads images in sequence, while jquery loads images in sequence.
Css code:
ul#portfolio{margin:0;padding:0;}ul#portfolio li{float: left;margin:0 5px 0 0;width:250px;height: 250px;list-style: none;}ul#portfolio li.loading{background: url(../images/spinner.gif) no-repeat center center;}ul#portfolio li img{width:250px;height: 250px;display: block;}
Js Code:
$ (Function () {var images = new Array (); images [0] = '. /images/ads_one.jpg '; images [1] = '. /images/ads_two.jpg '; images [2] = '. /images/ads_three.jpg '; // obtain the number of images var max =$ (images ). length; // if more than one image is contained, create the corresponding UL element family in the wrapper div and call the LoadImage method. If (max> 0) {// create the UL element var ul = $ ('<ul id = "portfolio"> </ul> '); // append to div # wrapper $ (ul ). appendTo ($ ('# wrapper'); // load the first image LoadImage (0, max);} // In the LoadImage method, traverse all the images cyclically, create the li element function LoadImage (index, max) {if (index <max) {// Add the css style for the li element using the attr method, that is, the gif background of loading is added. Var list = $ ('<li id = "portfolio _' + index + '"> </li> '). attr ('class', 'loading'); // Add li to the ul element $ ('ul # portfolio '). append (list); // obtain the current li element var curr =$ ("ul # portfolio li # portfolio _" + index ); // create the Image element var img = new Image (); // load the Image $ (img ). load (function () {publish (this).css ('display', 'None'); $ (curr ). removeClass ('loading '). append (this); $ (this ). fadeIn ('low', function () {// use the callback function. After the current element successfully executes the fadeIn method, call the LoadIma of the next element. Ge method to achieve sequential loading of multiple images. LoadImage (index + 1, max );});}). error (function () {$ (curr ). remove (); LoadImage (index + 1, max );}). attr ('src', images [index]) ;}})