mirror of
https://github.com/wassname/talk.git
synced 2026-08-15 12:55:10 +08:00
* feat: support lazy rendering * fix: added new env var to onbuild args * review: apply suggestions
21 lines
473 B
JavaScript
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);
|
|
}
|