Load multiple images to determine load completion status

Source: Internet
Author: User

var totalimages = tenvar loadedimages = 0;$ ('  '). Load (function() { ++if(loadedimages = = totalimages) {//}});

or refer to someone else's plugin code:

(function() {$.fn.imgload=function(options) {varopts =$.extend ({time:4000,///wait for load time, and execute callbacks directly if this time is exceededCallbackfunction(){}//Default Callback}, Options); var$ This= This, i = 0, j = 0, Len = This. Length; $ This. each (function(){            var_this = This, Datesrc= $ (_this). attr ("Date-src"), Imgsrc= Datesrc?datesrc:_this.src; varIMG =NewImage (); Img.onload=function() {img.onload=NULL; _THIS.SRC=imgsrc; I++;            }; IMG.SRC=imgsrc;        }); vart = Window.setinterval (function() {J++; $("#msg"). html (i); if(I==len | | j*200>=opts.time)                {window.clearinterval (t);            Opts.callback ();        }; },200); }}) (JQuery);

HTML structure

Note: The DATE-SRC attribute is the real picture address src put a loading ... GIF pictures, without date-src is also possible!!!

<imgdate-src= "Http://dl.yzz.cn/public/images/100608/29_161214_3.jpg"src= "Http://www.mb5u.com/uploads/sucai/20088258937562778016.gif" /><imgdate-src= "Http://www.asianfinancialforum.com/aff2010/eng/photos/images/large/p8.jpg"src= "Http://www.mb5u.com/uploads/sucai/20088258937562778016.gif"  /><imgdate-src= "Http://www.asianfinancialforum.com/aff2010/eng/photos/images/large/p13.jpg"src= "Http://www.mb5u.com/uploads/sucai/20088258937562778016.gif" />

Call

$ (function() {    $ ("img"). Imgload ({time        :10000000,// set large enough Must wait for the picture to be loaded, but at 404 the Cup has a        ... Callback:function() {            alert ("load Complete")}    })    

Load multiple images to determine load completion status

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.