wiki.techinc.nl/resources/lib/codex/modules/useIntersectionObserver.js

2 lines
546 B
JavaScript
Raw Normal View History

"use strict";const t=require("vue");function u(o,c){const e=t.ref(!1);let s=!1;if(typeof window!="object"||!("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype))return e;const n=new window.IntersectionObserver(r=>{const i=r[0];i&&(e.value=i.isIntersecting)},c);return t.onMounted(()=>{s=!0,o.value&&n.observe(o.value)}),t.onUnmounted(()=>{s=!1,n.disconnect()}),t.watch(o,r=>{s&&(n.disconnect(),e.value=!1,r&&n.observe(r))}),e}exports.useIntersectionObserver=u;