UNPKG

ice.fo.utils

Version:

24 lines (20 loc) 617 B
export default function waitForElementOnScreen(el) { return new Promise((resolve) => { const observer = new IntersectionObserver((entries) => { // Use `intersectionRatio` because of Edge 15's // lack of support for `isIntersecting`. // See: https://github.com/w3c/IntersectionObserver/issues/211 if (entries[0].intersectionRatio <= 0) { return; } // Cleanup the observer when it's not // needed anymore. observer.unobserve(el); resolve(); }); // Begin observer try { observer.observe(el); } catch (error) { resolve(); } }); }