How to use JavaScript to determine whether a picture is loaded

Source: Internet
Author: User

Sometimes you need to get the size of the picture, which needs to be done after the picture is loaded. There are three ways to achieve it, as described below.

First, the Load event

<! DOCTYPE html>    

Test, all browsers display "loaded", which means that all browsers support the IMG Load event.

Ii. ReadyStateChange Incident

<! DOCTYPE html>    

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

ReadyState for complete and loaded indicates that the picture has been loaded. The test Ie6-ie10 supports this event and is not supported by other browsers.

Three, the complete attribute of img

<! DOCTYPE html>    

Polling constantly monitors the IMG complete property, and if True indicates that the picture has been loaded and stops polling. This property is supported by all browsers.

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.