UNPKG

@opensig/opendesign

Version:

29 lines (28 loc) 647 B
import { ref, getCurrentInstance, onUnmounted } from "vue"; function useScrollState(opts = {}) { const { resetDelay = 150 } = opts; const isScrolling = ref(false); let endTimer; const markScrolling = () => { isScrolling.value = true; if (endTimer) { clearTimeout(endTimer); } endTimer = setTimeout(() => { isScrolling.value = false; endTimer = void 0; }, resetDelay); }; const cleanup = () => { if (endTimer) { clearTimeout(endTimer); } }; if (getCurrentInstance()) { onUnmounted(cleanup); } return { isScrolling, markScrolling, cleanup }; } export { useScrollState };