There are some error-prone methods of obtaining the size of dynamically loaded images. The main reasons for errors are:
You call the code before the image is downloaded from the web page. In this case, It is not easy to find when developing on the machine.
The BUG of jQuery load() event processing. When the image is obtained from the browser cache, the wrong size is obtained.
The wrong code is:
(Error ) Call the code to get the dimensions immediately after adding the HTML
(Error) Use jQuery’s load() event handling
The following is the truly correct method, using the JavaScript Image class:
Correct method