Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Intersection Observer + custom lazy loading demo
<html>
<head>
<title>Lazy loading by #Blondiecode</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, "Helvetica Neue", Helvetica, serif;
}
footer {
padding: 20px 0;
text-align: center;
}
h1, h2 {
width: 100%;
text-align: center;
}
a {
color: #777777;
}
a:hover {
color: #999999;
}
.wrapper {
width: 100%;
margin: 0 auto;
max-width: 1200px;
display: flex;
flex-wrap: wrap;
}
.item {
width: 25%;
box-sizing: border-box;
min-height: 400px;
min-width: 300px;
text-align: center;
}
.item.youtube {
width: 50%;
min-height: 315px;
overflow: visible;
}
.item.loading {
border: 1px dotted #a7a7a7;
position: relative;
}
.item.loading:after {
content: '';
position: absolute;
width: 50px;
left: 50%;
margin-left: -25px;
height: 50px;
top: 50%;
margin-top: -25px;
background: url("data:image/gif;base64,R0lGODlhZAANAOMAAHx+fNTS1JyenOzq7IyOjPz6/ISChKSipPz+/P///wAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQJCQAJACwAAAAAZAANAAAEyzDJSau9OOvNu/9gKI5kaZ7ohBQFYq3ty7oVTFO2HNezfqs93k4VEAgCP0TxmFwicc6m8UmcSplQaxZb5UoGBACAMKCAxWRzeFyenNlqdPu7Trvr88TbTpfH4RMBBgAGBgEUAYSEh4GKhoiOjBKJhI+NlZIJlIWZm5aTYpyQmH98enileXuqqHd+roB9saevsqZKWhMFURS7uRK+Xgm4wsRUEsZXx8O8XcvDLAUW0dIV1NPR2Cza1b3Z1t/e2+DjKebn6Onq6+zt7hYRACH5BAkJABYALAAAAABkAA0AhAQCBISChMzOzExKTOzq7BweHKSipNza3Hx6fPT29CwuLLSytPz+/AwODIyOjNTW1ExOTNze3Hx+fPz6/DQyNLS2tP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAX+oCWOZGmeaKqubMsyScK4dG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o0iTKu0ZAgAh+QQJCQATACwAAAAAZAANAIQEAgSEgoTU0tTs6uxEQkScnpzk4uT09vR0dnQUFhTc2tz8/vx8fnwEBgSMjozU1tSkoqT8+vx8enz///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAF9+AkjmRpnmiqrmzrvnAsz3Rt3/ISnfqxmL1fKQiM+IrHoVFIIiqTzWXpACEQCoemAAIRMCeLbfcb5nq1ZrL4PCqP0e/2Wp0eRRiAPICxEw0cDAwOAyR/gYOFgIKEI4aLiYeMfoqIjZSSE46Vk5EjBgl6AAkGIwIBgQECJKaoqqWnDKmrsLKvrbO3trGuIqy7uL8iCqF5D5adxwGbmYDKmIbOkI/H05zVzMjWm5+ho3J1cgVxImHibOQC5nTjYHNw5+3g6PIHCKEIfeQHUG1G+f0H/pHzB2SfQDAGCwZUeHBBQhIHCljBgqOixRoRDl7cyLGjx481QgAAOw==");
}
.item img {
width: 100%;
height: 400px;
}
.item.youtube img {
height: 315px;
}
</style>
</head>
<body>
<main class="wrapper js">
<h1>Some cool cats for you ❤</h1>
<div class="item loading">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" data-src="http://placekitten.com/600/800" alt="meow" width="300" height="400">
</div>
<div class="item loading">
<img data-src="https://dummyimage.com/300x400/82A3A1/fff.jpg&text=cat">
</div>
<div class="item loading">
<img data-src="http://placekitten.com/g/600/800">
</div>
<div class="item loading">
<img data-src="http://placekitten.com/600/799">
</div>
<div class="item loading">
<img data-src="https://dummyimage.com/300x400/C0DFA1/fff.jpg&text=kitty">
</div>
<div class="item loading">
<img data-src="http://placekitten.com/g/300/400">
</div>
<div class="item loading">
<img data-src="http://placekitten.com/g/300/399">
</div>
<div class="item loading">
<img data-src="https://dummyimage.com/300x400/b38cc9/fff.jpg&text=purrrr">
</div>
<div class="item loading">
<img data-src="http://placekitten.com/300/399">
</div>
<div class="item loading">
<img data-src="https://dummyimage.com/300x400/9FC490/fff.jpg&text=meow">
</div>
<div class="item loading">
<img data-src="http://placekitten.com/300/400">
</div>
<div class="item loading">
<img data-src="http://placekitten.com/g/900/1200">
</div>
<h2>Some cool videos from me with love ❤</h2>
<div class="item youtube loading">
<iframe width="560" height="315" data-src="https://www.youtube.com/embed/pAsOU6RV0Ys" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="item youtube loading">
<iframe width="560" height="315" data-src="https://www.youtube.com/embed/fQQDeNtQW-4" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</main>
<footer>
<small><a href="https://www.youtube.com/c/AidaDrogan" target="_blank">#BlondieCode © 2020</a></small>
</footer>
<script>
//============= dynamic placeholder for images
const placeholder = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
const targets = document.querySelectorAll('[data-src]');
targets.forEach(target => {
target.src = placeholder
});
//============= IntersectionObserver
const options = {
root: null,
rootMargin: '0px',
threshold: 0.05
};
const loadImage = function (entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting && entry.target.parentNode.classList.contains('loading')){
entry.target.src = entry.target.getAttribute('data-src');
entry.target.onload = () => {
entry.target.parentNode.classList.remove('loading');
entry.target.removeAttribute('data-src');
};
}
});
};
const observer = new IntersectionObserver(loadImage, options);
targets.forEach(target => {
observer.observe(target);
});
//============= lazy loading by Aida Drogan
// function isIntersecting(target) {
// const docViewTop = window.pageYOffset;
// const docViewBottom = docViewTop + window.innerHeight;
// const elemTop = docViewTop + target.getBoundingClientRect().top;
// const elemBottom = elemTop + target.height;
// return (((elemTop <= docViewBottom) && (elemTop >= docViewTop))
// || ((elemBottom <= docViewBottom) && (elemBottom >= docViewTop)));
// }
//
// const checkImages = function() {
// targets.forEach(target => {
// if (isIntersecting(target) && target.parentNode.classList.contains('loading')){
// target.src = target.getAttribute('data-src');
// target.onload = () => {
// target.parentNode.classList.remove('loading');
// target.removeAttribute('data-src');
// };
// }
// });
// };
//
// window.onload = checkImages;
// window.onscroll = checkImages;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment