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.