<div>
  <div class="hoge">hoge</div>
  <div id="piyo" class="fuga">piyo</div>
</div>
.hoge {
  height: 600px;
  width: 200px;
  background: #10bace;
}

.fuga {
  height: 600px;
  width: 200px;
  background: tomato;
}
const c = (entries) => window.alert('ちばけんま!');

const options = {
  root: null,
  rootMargin: '0px',
  threshold: 0,
};

const e = document.querySelector('#piyo');

const observer = new IntersectionObserver(c, options);
observer.observe(e);
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.