UNPKG

sveltfy

Version:

A material design framework/component library for Svelte, with full support for light and dark themes and customisability.

24 lines (23 loc) 546 B
export default (node, options) => { const settings = { once: false, ...options }; const observer = new IntersectionObserver((entries) => { const entry = entries[0]; const intersecting = entry.isIntersecting; if (intersecting) { node.dispatchEvent( new CustomEvent('intersect', { detail: entry, }), ); if (settings.once) { observer.unobserve(node); } } }, settings); observer.observe(node); return { destroy() { observer.unobserve(node); }, }; };