Home Web Front-end JS Tutorial Three ways to use JavaScript to determine whether an image has been loaded_javascript skills

Three ways to use JavaScript to determine whether an image has been loaded_javascript skills

May 16, 2016 pm 04:50 PM
Image loading

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

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.
Three ways to use JavaScript to determine whether an image has been loaded_javascript skills
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to optimize image loading failure display problem in Vue development How to optimize image loading failure display problem in Vue development Jun 29, 2023 am 10:51 AM

How to optimize the image loading failure display problem in Vue development. In Vue development, we often encounter scenarios where images need to be loaded. However, due to unstable network or non-existence of the image, it is very likely that the image will fail to load. Such problems not only affect the user experience, but may also lead to confusing or blank page presentation. In order to solve this problem, this article will share some methods to optimize the display of image loading failure in Vue development. Use default picture: In the Vue component, you can set a default picture,

How to solve the problem that Edge browser cannot load images How to solve the problem that Edge browser cannot load images Jan 30, 2024 am 10:54 AM

What should I do if the image cannot be loaded in the edge browser? The edge browser is the default browser used by many friends to surf the Internet, and can provide users with convenient Internet services. However, some friends found that the images in the webpage of the edge browser could not be loaded normally while surfing the Internet. After ruling out the network problem, the most likely problem is the setting. If you want to solve this problem, just follow the editor Let’s take a look at the solutions to why images cannot be displayed. What should I do if the image in the edge browser cannot be loaded? 1. Click Start in the lower left corner and right-click "Microsoft Edge". 2. Select "More" and click "App Settings". 3. Scroll down to find “Pictures”. 4. Turn on the switch below the picture.

Vue lazy loading image failure problem solution Vue lazy loading image failure problem solution Jun 29, 2023 pm 10:42 PM

How to solve the problem of lazy loading failure of images in Vue development Lazy loading (LazyLoad) is one of the optimization technologies commonly used in modern web development. Especially when loading a large number of images and resources, it can effectively reduce the burden on the page and improve the user experience. However, when developing using the Vue framework, sometimes we may encounter the problem of lazy loading of images failing. This article will introduce some common problems and solutions so that developers can better deal with this problem. Image resource path error First, we need to ensure that the image resource

How to solve the problem that Windows 11 Microsoft Store images cannot be loaded How to solve the problem that Windows 11 Microsoft Store images cannot be loaded Jun 29, 2023 pm 03:43 PM

How to solve the problem that Windows 11 Microsoft Store images cannot be loaded? In the Microsoft Store, we can easily search and download various software and games. However, recently some Win11 users have found that the Microsoft Store images on their computers cannot be loaded, which greatly affects the user experience. So is there any solution to this situation? What's the solution? Let’s take a look at how the editor solved it. Solution to the problem that Win11 Microsoft Store images cannot be loaded: 1. Right-click the start menu below to enter. 2. Click to select Network and Internet to enter. 3. You can check whether your network connection is normal. 4. You can change the network configuration from private to public.

How to use PHP development cache to optimize image loading speed How to use PHP development cache to optimize image loading speed Nov 08, 2023 pm 05:58 PM

How to use PHP to develop cache and optimize image loading speed. With the rapid development of the Internet, web page loading speed has become one of the important factors in user experience. Image loading speed is one of the important factors affecting web page loading speed. In order to speed up the loading of images, we can use PHP development cache to optimize the image loading speed. This article will introduce how to use PHP to develop cache to optimize image loading speed, and provide specific code examples. 1. Principle of cache Cache is a technology for storing data by temporarily storing data in high-speed memory.

How to solve the problem that web page images cannot be loaded How to solve the problem that web page images cannot be loaded Jan 08, 2024 pm 01:45 PM

When many friends open a webpage, they find that the pictures on the webpage cannot be loaded and an × mark is displayed. What is going on? It may be that your Internet speed is too low, just wait for a while, or it may be that the relevant mode is not turned on in the settings. Let’s take a look at the solutions to the problem of web page images not being loaded. The webpage image cannot be loaded: 1. Internet speed problem. The webpage cannot display the image. It may be because the computer's Internet speed is relatively slow, there are many softwares opened on the computer, and the images we access are relatively large, which may be due to the loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. If there are too many visitors and the webpage cannot display the picture, it may be because of the webpage we visited.

What should I do if the images I browse cannot be loaded in Windows 7? What should I do if the images I browse cannot be loaded in Windows 7? Jul 19, 2023 pm 02:57 PM

When you browse the web, have you ever encountered a situation where images cannot be loaded? So what is the reason? What should I do if the images I browse in Windows 7 cannot be loaded? For users who have this problem, please take a look at the following Xiaobian to share with you the solution to the problem that Win7 cannot load images when browsing. 1. First, we first determine whether the web page is set not to display images. We click Tools-Internet Options in the upper right corner of the browser and switch to Advanced. If we drag it to Multimedia, there will be an option to display images, which needs to be checked in front. 2. Next, let us check whether the flashplayer version is the latest version. Detection method. Click Start, then select Control Panel and find flashplaye in the Control Panel

PHP learning steps: How to optimize image loading PHP learning steps: How to optimize image loading Aug 18, 2023 pm 12:05 PM

PHP learning steps: How to optimize image loading In modern web development, optimizing image loading is an important topic. With the development of web design, images have become an integral part of the page. However, images that are too large or not optimized may cause web pages to load slowly, affecting the user experience. Therefore, learning how to optimize image loading is a skill that every PHP developer should master. The following will introduce some commonly used methods to optimize image loading and corresponding PHP code examples. We'll start with compressed images, lazy loading, and byte

See all articles