Created
June 24, 2019 09:22
-
-
Save JRaspass/da6d2c843e3a908ad591ae9dd8925b69 to your computer and use it in GitHub Desktop.
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
| 'use strict'; | |
| const imgs = document.querySelectorAll('[data-src]'); | |
| if ('IntersectionObserver' in window) { | |
| const observer = new IntersectionObserver(entries => { | |
| for (const entry of entries) | |
| if (entry.isIntersecting) { | |
| entry.target.src = entry.target.dataset.src; | |
| observer.unobserve(entry.target); | |
| } | |
| }); | |
| imgs.forEach(e => observer.observe(e)); | |
| } | |
| else | |
| imgs.forEach(e => e.src = e.dataset.src); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment