UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

33 lines (32 loc) 820 B
import { useIntersectionObserver } from "@vueuse/core"; import { onMounted } from "vue"; const useIntersection = (el, onIntersect) => { const calculateRootMargin = (element) => { const height = element.offsetHeight; return `${height / 2}px 0px ${height / 2}px 0px`; }; const calculateThreshold = (element) => { const height = element.offsetHeight; return height < window.innerHeight ? 0.8 : 0.5; }; onMounted(() => { if (el.value) { const options = { rootMargin: calculateRootMargin(el.value), threshold: calculateThreshold(el.value) }; useIntersectionObserver( el, ([entry]) => { if (entry?.isIntersecting) { onIntersect(); } }, options ); } }); }; export { useIntersection };