mirror of
https://github.com/umami-software/umami.git
synced 2026-02-13 09:05:36 +01:00
Fix sticky header calc.
This commit is contained in:
parent
f4ca353b5c
commit
dc267f8daa
1 changed files with 4 additions and 4 deletions
|
|
@ -10,15 +10,15 @@ export default function StickyHeader({
|
||||||
}) {
|
}) {
|
||||||
const [sticky, setSticky] = useState(false);
|
const [sticky, setSticky] = useState(false);
|
||||||
const ref = useRef();
|
const ref = useRef();
|
||||||
const offsetTop = useRef(0);
|
const top = useRef(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkPosition = () => {
|
const checkPosition = () => {
|
||||||
if (ref.current) {
|
if (ref.current) {
|
||||||
if (!offsetTop.current) {
|
if (!top.current) {
|
||||||
offsetTop.current = ref.current.offsetTop;
|
top.current = ref.current.offsetTop + ref.current.offsetHeight;
|
||||||
}
|
}
|
||||||
const state = window.pageYOffset > offsetTop.current;
|
const state = window.pageYOffset > top.current;
|
||||||
if (sticky !== state) {
|
if (sticky !== state) {
|
||||||
setSticky(state);
|
setSticky(state);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue