Home  >  Article  >  Web Front-end  >  About JS method to determine whether the image is loaded and get the width of the image_javascript skills

About JS method to determine whether the image is loaded and get the width of the image_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:37:461122browse

Students who work on the web often encounter situations where customers upload pictures that burst the content area of ​​the web page. Here is a way to use js to deal with this problem. The specific idea is to judge the client's pictures in js After downloading, do some processing on the width or height of the image in a timely manner. JS processing of images mainly uses the Image object in JS to judge through the onload event and onreadystatechange.

(1) The first method, through the onload event, such as:

Copy the code The code is as follows:



(2) The second method, use onreadystatechange to judge

Copy code The code is as follows:


onloading……

Statement:
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