Adds the Lifestyle fotografie section to the homepage
Adds the first block below the hero: heading, intro and a staggered gallery of four live photos. Brings in the shared section building blocks (HomeSection, SectionHeading, Reveal) and DeferredImage, which holds back below-the-fold photos until the page has loaded so they do not compete with the hero for bandwidth. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
type UseInViewOptions = {
|
||||
threshold?: number;
|
||||
rootMargin?: string;
|
||||
// Skip observing and report "in view" right away
|
||||
skip?: boolean;
|
||||
};
|
||||
|
||||
// Tells whether an element has come into (or near) the viewport, once.
|
||||
// Without IntersectionObserver the element counts as in view right away, so
|
||||
// content is never left hidden or unloaded.
|
||||
export default function useInView<T extends Element>({
|
||||
threshold = 0,
|
||||
rootMargin = '0px',
|
||||
skip = false,
|
||||
}: UseInViewOptions = {}) {
|
||||
const ref = useRef<T>(null);
|
||||
const supported = typeof IntersectionObserver !== 'undefined';
|
||||
const [intersected, setIntersected] = useState(false);
|
||||
const immediate = skip || !supported;
|
||||
|
||||
useEffect(() => {
|
||||
const element = ref.current;
|
||||
if (!element || immediate || intersected) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
if (entries.some((entry) => entry.isIntersecting)) {
|
||||
setIntersected(true);
|
||||
observer.disconnect();
|
||||
}
|
||||
},
|
||||
{ threshold, rootMargin },
|
||||
);
|
||||
observer.observe(element);
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, [immediate, intersected, threshold, rootMargin]);
|
||||
|
||||
return { ref, inView: immediate || intersected };
|
||||
}
|
||||
Reference in New Issue
Block a user