Skip to content

Instantly share code, notes, and snippets.

@Phongtlam
Created March 27, 2019 00:19
Show Gist options
  • Save Phongtlam/fcf58ee8223ee95f98dfe4a7c8fafe6f to your computer and use it in GitHub Desktop.
Save Phongtlam/fcf58ee8223ee95f98dfe4a7c8fafe6f to your computer and use it in GitHub Desktop.
initIntersectionObserver
const initIntersectionObserver = () => {
const options = {
/* root: document.querySelector(".cat-list") */
}
const callback = entries => {
entries.forEach(entry => {
if (entry.target.id === 'cat-tile-0') {
topSentCallback(entry);
} else if (entry.target.id === `cat-tile-${listSize - 1}`) {
botSentCallback(entry);
}
});
}
var observer = new IntersectionObserver(callback, options);
observer.observe(document.querySelector("#cat-tile-0"));
observer.observe(document.querySelector(`#cat-tile-${listSize - 1}`));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment