Files
talk/client/coral-embed/src/onIntersect.js
T
Kiwi 362f29f77e Support lazy rendering (#2109)
* feat: support lazy rendering

* fix: added new env var to onbuild args

* review: apply suggestions
2018-12-06 21:24:31 +00:00

21 lines
473 B
JavaScript

export default function onIntersect(el, callback) {
if (!IntersectionObserver) {
// tslint:disable-next-line:no-console
console.warn('IntersectionObserver not available');
callback();
return;
}
const options = {
rootMargin: '100px',
threshold: 1.0,
};
const observer = new IntersectionObserver(entries => {
if (entries[0].isIntersecting) {
observer.disconnect();
callback();
}
}, options);
observer.observe(el);
}