<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="https://www.takurinton.com/me.jpeg" type="image/x-icon">
    <title>Document</title>
    <style>
        body {
            margin: 50px 0;
            padding: 0;
        }
    </style>
</head>
<body>

    <div id="box1" class="hoge" style="margin: 100px; height: 500px; width: 300px; background-color: aqua;"><p class="content"></p></div>
    <div id="box2" class="hoge" style="margin: 100px; height: 500px; width: 300px; background-color: aqua;"><p class="content"></p></div>
    <div id="box3" class="hoge" style="margin: 100px; height: 500px; width: 300px; background-color: aqua;"><p class="content"></p></div>
    <div id="box4" class="hoge" style="margin: 100px; height: 500px; width: 300px; background-color: aqua;"><p class="content"></p></div>
    <script async defer src="./index.js"></script>
</body>
</html> 
const options = {
  root: null,
  rootMargin: '0px',
  threshold: [0.2],
}

const observer = new IntersectionObserver((targets) => {
    for (const target of targets) {
      if (target.isIntersecting) {
        console.log(`${target.target.id} is intersecting`)
      }
    };
}, options);

const targets = document.querySelectorAll('.hoge');
targets.forEach(target => observer.observe(target)); 

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.