UNPKG

@opensig/opendesign

Version:

33 lines (32 loc) 1.01 kB
import { onMounted, onBeforeUnmount } from "vue"; import { until } from "@vueuse/core"; function useWheel(opts) { const { wrapperRef, isHorizontal, axis } = opts; const onWheel = (e) => { const el = wrapperRef.value; if (!el) { return; } const scrollPos = axis.getScroll(el); const maxScroll = axis.getScrollSize(el) - axis.getClientSize(el); const atStartEdge = scrollPos <= 0; const atEndEdge = scrollPos >= maxScroll; const delta = isHorizontal.value ? e.deltaX || (e.shiftKey ? e.deltaY : 0) : e.deltaY; if (atStartEdge && delta < 0 || atEndEdge && delta > 0) { e.preventDefault(); } }; onMounted(() => { until(wrapperRef).toBeTruthy().then(() => { var _a; (_a = wrapperRef.value) == null ? void 0 : _a.addEventListener("wheel", onWheel, { passive: false }); }); }); onBeforeUnmount(() => { var _a; (_a = wrapperRef.value) == null ? void 0 : _a.removeEventListener("wheel", onWheel); }); } export { useWheel };