Home > Article > Web Front-end > About JS method to determine whether the image is loaded and get the width of the image_javascript skills
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:
(2) The second method, use onreadystatechange to judge