Sphere
Log in Join
☆ 17

IntersectionObserver reveal animation flickers when scrolling back

Cards fade in on scroll with a class added by IntersectionObserver. When I scroll up and down they flicker because the class is removed and re-added. Should the effect be one-time?

⚑ Report

3 replies

☆ 0
F fern42 ·2026-10-25#1

Call observer.unobserve(entry.target) after adding the class. A reveal is usually a one-time entrance, not a state tied to visibility.

⚑ Report
☆ 0
R raven42 ·2026-10-25#2

I actually wanted it to replay when cards come back into view.

⚑ Report
☆ 0
M Mike ·2026-10-25#3

Then use a different class for the hidden state and apply it only when the element leaves by more than a threshold. Simpler: keep it one-time; replaying motion is often annoying.

⚑ Report
Log in to reply.