Home > Web Front-end > JS Tutorial > body text

How does JavaScript determine whether an image has been loaded in order to obtain its size_javascript skills

WBOY
Release: 2016-05-16 16:49:20
Original
1125 people have browsed it

Sometimes it is necessary to obtain the size of an image. This needs to be done after the image is loaded. How can I do this?

1. Load event

Copy code The code is as follows:

< !DOCTYPE HTML>



img - load event



loading...






Tested, all browsers show "loaded" indicates that all browsers support the load event of img.

2. readystatechange event
Copy code The code is as follows:

< !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
Copy code The code is as follows:





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.
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!