About the HTMLImageElement.complete property

I learned about this Boolean JavaScript property from today’s Web Tools Weekly newsletter (which you should definitely subscribe to). Louis Lazaris offers this example: That’s a simple test that returns true or false based on whether the image has completed rendering. That sounds like a fantastic use case for something like displaying a placeholder image […]

The post About the HTMLImageElement.complete property appeared first on Geoff Graham.


This content originally appeared on Geoff Graham and was authored by Geoff Graham

I learned about this Boolean JavaScript property from today’s Web Tools Weekly newsletter (which you should definitely subscribe to). Louis Lazaris offers this example:

let myImage = document.querySelector('#myImage');

// will display true or false
console.log(myImage.complete);

That’s a simple test that returns true or false based on whether the image has completed rendering. That sounds like a fantastic use case for something like displaying a placeholder image or element while the image is loading. Images often loading pretty quickly, though, so it would be less of a visual enhancement than perhaps a way to avoid nasty content jumps as images load.

Then again, there are already ways to combat content jumps and layout shifts. And we’re talking about the slowest of slow connections. Louis created a demo over at CodePen and suggests emulating a slower internet connection, say in DevTools.

Screenshot of Chrome's DevTools open to the Network settings showing the options to throttle the internet speed.
Enable “throttling” in the DevTools Network tab in Chrome.

Source

The post About the HTMLImageElement.complete property appeared first on Geoff Graham.


This content originally appeared on Geoff Graham and was authored by Geoff Graham


Print Share Comment Cite Upload Translate Updates
APA

Geoff Graham | Sciencx (2022-02-24T17:54:13+00:00) About the HTMLImageElement.complete property. Retrieved from https://www.scien.cx/2022/02/24/about-the-htmlimageelement-complete-property/

MLA
" » About the HTMLImageElement.complete property." Geoff Graham | Sciencx - Thursday February 24, 2022, https://www.scien.cx/2022/02/24/about-the-htmlimageelement-complete-property/
HARVARD
Geoff Graham | Sciencx Thursday February 24, 2022 » About the HTMLImageElement.complete property., viewed ,<https://www.scien.cx/2022/02/24/about-the-htmlimageelement-complete-property/>
VANCOUVER
Geoff Graham | Sciencx - » About the HTMLImageElement.complete property. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/24/about-the-htmlimageelement-complete-property/
CHICAGO
" » About the HTMLImageElement.complete property." Geoff Graham | Sciencx - Accessed . https://www.scien.cx/2022/02/24/about-the-htmlimageelement-complete-property/
IEEE
" » About the HTMLImageElement.complete property." Geoff Graham | Sciencx [Online]. Available: https://www.scien.cx/2022/02/24/about-the-htmlimageelement-complete-property/. [Accessed: ]
rf:citation
» About the HTMLImageElement.complete property | Geoff Graham | Sciencx | https://www.scien.cx/2022/02/24/about-the-htmlimageelement-complete-property/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.