Javascript or jquery: Determine whether the image is loaded. Implementation Code _ javascript skills

Source: Internet
Author: User
The width and height of the image need to be obtained. Some js or jquery code is executed before the image is loaded. How can this problem be solved? Next we will introduce the methods provided by js and jquery. Sometimes, the webpage needs to obtain the width and height of the image to define some sizes. However, this requires requesting images from the server, download to the local machine. Some js or jquery code is executed before the image is loaded. What should we do?

Jquery provides a method:

The 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:

The 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.