Skip to content

Commit

Permalink
created optimizations for fire image animation
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmonisit committed Feb 4, 2024
1 parent 5bf75bf commit 4a2330e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions app/(landing)/sections/Hero/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ const animationTime = 700;

export default function Hero() {
const [currentImageIndex, setCurrentImageIndex] = useState(0);
const [completelyLoadedImages, setCompletedLoadedImages] = useState(0);

useEffect(() => {
const intervalId = setInterval(() => {
setCurrentImageIndex((prevIndex) => (prevIndex + 1) % FIRE_IMG.length);
}, animationTime);
let intervalId: NodeJS.Timeout | undefined;

return () => clearInterval(intervalId);
}, []);
if (completelyLoadedImages >= 3) {
intervalId = setInterval(() => {
setCurrentImageIndex((prevIndex) => (prevIndex + 1) % FIRE_IMG.length);
}, animationTime);
}


return () => {
if (intervalId) {
clearInterval(intervalId);
}
};
}, [completelyLoadedImages]);

return (
<>
Expand Down Expand Up @@ -62,6 +72,9 @@ export default function Hero() {
"opacity-0 absolute": currentImageIndex !== 0,
})}
priority
onLoad={() => {
setCompletedLoadedImages((prev) => prev + 1);
}}
/>
<Image
src={FIRE_IMG[1]}
Expand All @@ -74,7 +87,9 @@ export default function Hero() {
"opacity-100": currentImageIndex === 1,
"opacity-0 absolute ": currentImageIndex !== 1,
})}
priority
onLoad={() => {
setCompletedLoadedImages((prev) => prev + 1);
}}
/>
<Image
src={FIRE_IMG[2]}
Expand All @@ -87,7 +102,9 @@ export default function Hero() {
"opacity-100": currentImageIndex === 2,
"opacity-0 absolute ": currentImageIndex !== 2,
})}
priority
onLoad={() => {
setCompletedLoadedImages((prev) => prev + 1);
}}
/>
</div>
</>
Expand Down
Binary file modified public/landing/Fire1.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/landing/Fire2.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/landing/Fire3.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4a2330e

Please sign in to comment.