mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-25 06:54:43 +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 { useLayoutEffect, useRef, useState } from 'preact/hooks';
|
||||||
import { useInView } from 'react-intersection-observer';
|
import { useInView } from 'react-intersection-observer';
|
||||||
|
|
||||||
|
// The sticky header, usually at the top
|
||||||
|
const TOP = 48;
|
||||||
|
|
||||||
export default function LazyShazam({ children }) {
|
export default function LazyShazam({ children }) {
|
||||||
const containerRef = useRef();
|
const containerRef = useRef();
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
|
@ -11,6 +14,7 @@ export default function LazyShazam({ children }) {
|
||||||
|
|
||||||
const { ref } = useInView({
|
const { ref } = useInView({
|
||||||
root: null,
|
root: null,
|
||||||
|
rootMargin: `-${TOP}px 0px 0px 0px`,
|
||||||
trackVisibility: true,
|
trackVisibility: true,
|
||||||
delay: 1000,
|
delay: 1000,
|
||||||
onChange: (inView) => {
|
onChange: (inView) => {
|
||||||
|
@ -25,7 +29,7 @@ export default function LazyShazam({ children }) {
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (!containerRef.current) return;
|
if (!containerRef.current) return;
|
||||||
const rect = containerRef.current.getBoundingClientRect();
|
const rect = containerRef.current.getBoundingClientRect();
|
||||||
if (rect.bottom > 0) {
|
if (rect.bottom > TOP) {
|
||||||
setVisibleStart(true);
|
setVisibleStart(true);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
Loading…
Add table
Reference in a new issue