Skip to content

Instantly share code, notes, and snippets.

@Dexdot
Created April 26, 2019 09:19
Show Gist options
  • Select an option

  • Save Dexdot/908f54c02d9a940064c152fc8a9e5c35 to your computer and use it in GitHub Desktop.

Select an option

Save Dexdot/908f54c02d9a940064c152fc8a9e5c35 to your computer and use it in GitHub Desktop.
IO
// Options
const options = {
threshold: [0, 0.25, 0.5, 0.75, 1]
};
const animateItem = item => item.target.classList.add('visible');
// Create observer
const observer = new IntersectionObserver(items => {
items.forEach(item => {
if (item.isIntersecting) {
animateItem(item);
}
});
}, options);
// Start observe
const elements = document.querySelectorAll('.js-observe');
elements.forEach(el => {
observer.observe(el);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment