<div>
  <div class="hoge">hoge</div>
  <div id="piyo" class="fuga">piyo</div>
</div>
@keyframes fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}

.unko {
  animation: 1s fadein;
}

.hoge {
  height: 600px;
  width: 200px;
  background: #10bace;
}

.fuga {
  width: 200px;
  height: 600px;
  background: tomato;
}
const c = (entries: IntersectionObserverEntry[]) =>
  entries
    .filter((e) => e.isIntersecting)
    .forEach((e) => e.target.classList.add('unko'));

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

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

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

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.