mirror of
https://github.com/wassname/talk.git
synced 2026-07-20 12:40:47 +08:00
* feat: refactored bridge - Cleaned up implementation of bridge - Removed unneeded babel-polyfill and webpack globals * fix: fixed up some static headers - bumped version * fix: moved intersection observer out of chunk * fix: fixed misplaced "!"
31 lines
802 B
JavaScript
31 lines
802 B
JavaScript
export default function onIntersect(el, callback) {
|
|
// Ensure that the intersection observer is available.
|
|
if (!IntersectionObserver) {
|
|
// tslint:disable-next-line:no-console
|
|
window.console.warn('IntersectionObserver not available, rendering now');
|
|
callback();
|
|
return;
|
|
}
|
|
|
|
// Create the Intersection Observer that will wait till the embed is within
|
|
// view and will then call the callback.
|
|
const observer = new IntersectionObserver(
|
|
entries => {
|
|
if (entries[0].isIntersecting) {
|
|
// Stop receiving intersection events.
|
|
observer.disconnect();
|
|
|
|
// Fire the callback.
|
|
callback();
|
|
}
|
|
},
|
|
{
|
|
rootMargin: '100px',
|
|
threshold: 1.0,
|
|
}
|
|
);
|
|
|
|
// Start observing the element for visibility.
|
|
observer.observe(el);
|
|
}
|