mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-01-22 16:46:28 +01:00
Make lazy shazam ignore top sticky header
This commit is contained in:
parent
e3c25d25ee
commit
960dff8b9e
1 changed files with 5 additions and 1 deletions
|
@ -4,6 +4,9 @@
|
|||
import { useLayoutEffect, useRef, useState } from 'preact/hooks';
|
||||
import { useInView } from 'react-intersection-observer';
|
||||
|
||||
// The sticky header, usually at the top
|
||||
const TOP = 48;
|
||||
|
||||
export default function LazyShazam({ children }) {
|
||||
const containerRef = useRef();
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
@ -11,6 +14,7 @@ export default function LazyShazam({ children }) {
|
|||
|
||||
const { ref } = useInView({
|
||||
root: null,
|
||||
rootMargin: `-${TOP}px 0px 0px 0px`,
|
||||
trackVisibility: true,
|
||||
delay: 1000,
|
||||
onChange: (inView) => {
|
||||
|
@ -25,7 +29,7 @@ export default function LazyShazam({ children }) {
|
|||
useLayoutEffect(() => {
|
||||
if (!containerRef.current) return;
|
||||
const rect = containerRef.current.getBoundingClientRect();
|
||||
if (rect.bottom > 0) {
|
||||
if (rect.bottom > TOP) {
|
||||
setVisibleStart(true);
|
||||
}
|
||||
}, []);
|
||||
|
|
Loading…
Reference in a new issue