Last active
June 28, 2026 23:45
-
-
Save jnicol/d5434130c8ae4893f332aae284bb35dc to your computer and use it in GitHub Desktop.
Animate native loading="lazy" images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Source: https://medienbaecker.com/articles/animate-native-lazy-loading | |
| <style> | |
| @media (scripting: enabled) { | |
| [loading="lazy"] { | |
| opacity: 0; | |
| transition: opacity 0.5s; | |
| } | |
| } | |
| </style> | |
| <img src="image.jpg" width="800" height="600" loading="lazy"> | |
| <script> | |
| document.querySelectorAll('[loading="lazy"]').forEach(element => { | |
| const animateIn = () => { | |
| element.style.opacity = 1; | |
| }; | |
| if (element.complete) { | |
| animateIn(); | |
| } else { | |
| element.addEventListener('load', animateIn); | |
| } | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment