Jquery loads images in sequence, while jquery loads images in sequence.

Source: Internet
Author: User

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]) ;}})

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.