Skip to content

Instantly share code, notes, and snippets.

@bob-lee
Created November 24, 2017 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bob-lee/63508ff17b665dd43cc501a359267658 to your computer and use it in GitHub Desktop.
Save bob-lee/63508ff17b665dd43cc501a359267658 to your computer and use it in GitHub Desktop.
IntersectionObserver setup 4
function observe(me) { // observe new element, me
if (!me) {
return;
}
const index = me.getAttribute('data-idx');
if (index == indexToObserve) {
elementToObserve = me;
intersectionObserver.observe(me);
console.info('elementToObserve', index);
} else {
console.log('observe(' + index + ' !== ' + indexToObserve + ')');
}
}
function unobserve() { // unobserve current element
if (elementToObserve) {
intersectionObserver.unobserve(elementToObserve);
intersectionRatio = undefined;
console.info('unobserve [' + indexToObserve + ']');
} else {
console.log('null elementToObserve');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment