mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
More deletes. Fixed sticky header.
This commit is contained in:
parent
87bbaa7f1d
commit
45c13da262
23 changed files with 69 additions and 582 deletions
27
hooks/useSticky.js
Normal file
27
hooks/useSticky.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { useState, useEffect, useRef } from 'react';
|
||||
|
||||
export default function useSticky(defaultSticky = false) {
|
||||
const [isSticky, setIsSticky] = useState(defaultSticky);
|
||||
const ref = useRef(null);
|
||||
const initialTop = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
if (window.pageYOffset > initialTop.current) {
|
||||
setIsSticky(true);
|
||||
} else {
|
||||
setIsSticky(false);
|
||||
}
|
||||
};
|
||||
|
||||
initialTop.current = ref.current.offsetTop;
|
||||
|
||||
window.addEventListener('scroll', handleScroll);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('scroll', handleScroll);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return { ref, isSticky };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue