tav-ui
Version:
44 lines (39 loc) • 943 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
function useIntersectionObserver({
target,
root,
onIntersect,
rootMargin = "0px",
threshold = 0.1
}) {
let cleanup = () => {
};
const observer = vue.ref(null);
const stopEffect = vue.watchEffect(() => {
cleanup();
observer.value = new IntersectionObserver(onIntersect, {
root: root ? root.value : null,
rootMargin,
threshold
});
const current = target.value;
current && observer.value.observe(current);
cleanup = () => {
if (observer.value) {
observer.value.disconnect();
target.value && observer.value.unobserve(target.value);
}
};
});
return {
observer,
stop: () => {
cleanup();
stopEffect();
}
};
}
exports.useIntersectionObserver = useIntersectionObserver;
//# sourceMappingURL=useIntersectionObserver2.js.map