feat(global) project init
This commit is contained in:
commit
3556eaed5e
22 files changed
+637
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
const useScroll = () => {
|
||||
const [ isScrolledX, setIsScrolledX ] = useState(false);
|
||||
const [ isScrolledY, setIsScrolledY ] = useState(false);
|
||||
const [ scrollX, setScrollX ] = useState(0);
|
||||
const [ scrollY, setScrollY ] = useState(0);
|
||||
|
||||
const handleScroll = () => {
|
||||
const x = window.scrollX;
|
||||
const y = window.scrollY;
|
||||
|
||||
setScrollX(x);
|
||||
setScrollY(y);
|
||||
setIsScrolledX(x > 0);
|
||||
setIsScrolledY(y > 0);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener('scroll', handleScroll);
|
||||
|
||||
// Cleanup listener on unmount
|
||||
return () => {
|
||||
window.removeEventListener('scroll', handleScroll);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [ isScrolledX, isScrolledY, scrollX, scrollY ];
|
||||
};
|
||||
|
||||
export default useScroll;
|
||||
Reference in new issue
Block a user