ethereal,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
body {
width: 3000px;
height: 3000px;
}
.element {
width: 300px;
height: 300px;
float: left;
margin: 10px;
background: coral;
transition: 1s;
}
.visible.element {
background: skyblue;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
const lazyAnimate = divs =>
divs.forEach(el => el.target.classList.toggle('visible', el.intersectionRatio > 0.4));
let observer = new IntersectionObserver(lazyAnimate, {
rootMargin: "10px",
threshold: [.3, 1.0]
});
let container = document.querySelectorAll('.element');
container.forEach(div => observer.observe(div))
});
</script>
</head>
<body>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
</body>
</html>