Zap modal (#209)
This commit is contained in:
22
src/Hooks/useHorizontalScroll.tsx
Normal file
22
src/Hooks/useHorizontalScroll.tsx
Normal file
@ -0,0 +1,22 @@
|
||||
import { useEffect, useRef, WheelEvent, LegacyRef } from "react";
|
||||
|
||||
function useHorizontalScroll() {
|
||||
const elRef = useRef<HTMLDivElement>();
|
||||
useEffect(() => {
|
||||
const el = elRef.current;
|
||||
if (el) {
|
||||
const onWheel = (ev: WheelEvent) => {
|
||||
if (ev.deltaY == 0) return;
|
||||
ev.preventDefault();
|
||||
el.scrollTo({ left: el.scrollLeft + ev.deltaY, behavior: "smooth" });
|
||||
};
|
||||
// @ts-ignore
|
||||
el.addEventListener("wheel", onWheel);
|
||||
// @ts-ignore
|
||||
return () => el.removeEventListener("wheel", onWheel);
|
||||
}
|
||||
}, []);
|
||||
return elRef as LegacyRef<HTMLDivElement> | undefined
|
||||
}
|
||||
|
||||
export default useHorizontalScroll;
|
Reference in New Issue
Block a user