JavaScript controls how the callback function is invoked after the picture is loaded _javascript tips

Source: Internet
Author: User

This example describes a method for invoking a callback function after a JavaScript control picture is loaded. Share to everyone for your reference. The specific analysis is as follows:

This code can control the execution of the specified callback function after the picture loading is complete in the specified range.

Copy Code code as follows:
function when_images_loaded ($img _container, callback) {
/* Do callback the images in $img _container (JQuery object) are loaded. _container are newly inserted images and this function are called after image images s are inserted into the target. */
var _imgs = $img _container.find (' img '),
Img_length = _imgs.length,
img_load_cntr = 0;
if (img_length) {//if the $img _container contains new images.
_imgs.on (' Load ', function () {//then We avoid the callback until images are loaded
img_load_cntr++;
if (img_load_cntr = = img_length) {
Callback ();
}
});
}
else {//otherwise Just does the main callback action if there ' no images in $img _container.
Callback ();
}
}

I hope this article will help you with your JavaScript programming.

Related Article

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.