feat: implement useMouseWheel composable
This commit is contained in:
15
app/composables/useMouseWheel.ts
Normal file
15
app/composables/useMouseWheel.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export type MouseWheelCallback = (deltaY: number, deltaX: number) => void;
|
||||||
|
|
||||||
|
export const useMouseWheel = (callback: MouseWheelCallback) => {
|
||||||
|
const handleWheel = (event: WheelEvent) => {
|
||||||
|
callback(event.deltaY, event.deltaX);
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
window.addEventListener("wheel", handleWheel, { passive: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
window.removeEventListener("wheel", handleWheel);
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user