Small Bug Fixes

This commit is contained in:
IM23a-spirgif
2025-03-13 10:27:54 +01:00
parent ab00298eee
commit 687ddedef1
7 changed files with 50 additions and 27 deletions
-4
View File
@@ -6,25 +6,21 @@ const FadeInSection = ({ children }) => {
const domRef = useRef();
const [hasBeenVisible, setHasBeenVisible] = useState(false);
const [opacity, setOpacity] = useState(0);
useEffect(() => {
const thresholds = Array.from({ length: 101 }, (_, i) => i / 100);
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
// If 30% or more of the element is visible and it hasn't been set visible before...
if (entry.intersectionRatio >= 0.3 && !hasBeenVisible) {
setHasBeenVisible(true);
setOpacity(1);
} else if (!hasBeenVisible) {
// Gradually update opacity until the threshold is met
setOpacity(entry.intersectionRatio);
}
});
},
{
threshold: thresholds,
// A slight negative bottom margin delays the fade until more of the section is in view
rootMargin: "0px 0px -20% 0px",
}
);