svelty-material
Version:
Svelte Materialify fork with ts support and updated scss.
23 lines (22 loc) • 625 B
JavaScript
export default (node, options) => {
const s = {};
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);
},
};
};