/** * Vue Composable for getting scroll distance * @module composables/scrollDistance */ /** * Vue Composable for getting scroll distance of client * @returns {globalThis.Ref} reference to the scroll distance value */ function useScrollDistance() { const scrollDistance = ref(0); function update() { if (import.meta.client) { scrollDistance.value = window.scrollY; } } onMounted(() => { update(); window.addEventListener("scroll", update); }); onUnmounted(() => window.removeEventListener("scroll", update)); return scrollDistance; } export { useScrollDistance };