Js or jquery determine whether the image is loaded to complete the implementation code

Source: Internet
Author: User

Sometimes the width and height of an image are required to define the size of the image on the webpage. However, you need to request the image from the server and download it to the local device, some js or jquery code is executed before the image is loaded. What should we do?

Jquery provides a method:Copy codeThe Code is as follows: 01. $ (""). load (function (){...});

The selector is the image id or class, and the method in the function is the callback function, which is executed after the image is loaded. However, I have tried a lot and the root cause is not that, the correct solution is:

Use the onload method of js:Copy codeThe Code is as follows: document. getElementById (""). onload = function (){};

The experiment results are feasible.

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.