Sometimes you need to get the size of the image, which needs to be done after the image is loaded. There are three ways to achieve this, which are introduced one by one below.
1. Load event
< !DOCTYPE HTML>
img - load event
loading...
Tested, all browsers show "loaded" indicates that all browsers support the load event of img.
2. readystatechange event
< !DOCTYPE HTML>
img - readystatechange event
loading...
readyState is complete and loaded indicates that the image has been loaded. Tested that IE6-IE10 support this event, other browsers do not support it.
3. Complete attribute of img
img - complete attribute
loading...
Polling continuously monitors the complete attribute of img. If it is true, it indicates that the image has been loaded and stops polling. This attribute is supported by all browsers.