Created
March 27, 2019 00:19
-
-
Save Phongtlam/fcf58ee8223ee95f98dfe4a7c8fafe6f to your computer and use it in GitHub Desktop.
initIntersectionObserver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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