Hi there,
I tried to create an image sequence and it works, but only with the html <img/>
tag and not with the Next/Image component.
Actually it works with the Next/Image component but only in dev mode and it works much better then the html <img/>
tag, because I can specify the loading priority etc.
However when I deploy the application the images in the image sequence can not be found when I use the Next/Image component.
This is the Next/Image component, much faster then the tag, but it´s not working in production mode:
return (
<>
<div className="scroll-img__container">
<div className="scroll-img__wrapper">
<Image
src={`/images/img-sequence/${scrolled
.toString()
.padStart(4, '0')}.webp`}
layout="fill"
className="img-sequence"
priority={true}
quality={1}
alt="img sequence"
/>
</div>
</div>
</>
);
It works with the <img/>
tag, also in production mode:
return (
<>
<div className="scroll-img__container">
<div className="scroll-img__wrapper">
<img
src={`./images/img-sequence/${scrolled
.toString()
.padStart(4, '0')}.webp`}
className="img-sequence"
/>
</div>
</div>
</>
);
This is the entire code for the scroll sequence:
import { useEffect, useState } from 'react';
import Image from 'next/image';
export default function Home() {
const [count, setCount] = useState(0);
const [scrolled, setScrolled] = useState(0);
useEffect(() => {
window.addEventListener('scroll', scrollProgress);
return () => window.removeEventListener('scroll', scrollProgress);
}, []);
const scrollProgress = () => {
const scrollPx = document.documentElement.scrollTop;
const windowHeightPx =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
const scrollLength = Math.ceil(((scrollPx / windowHeightPx) * 90) / 1);
setScrolled(scrollLength);
};
// useEffect(() => {
// if (count < 90) {
// setTimeout(() => {
// setCount(count + 1);
// }, 50);
// } else {
// setCount(1);
// }
// }, [count]);
return (
<>
<div className="scroll-img__container">
<div className="scroll-img__wrapper">
{/* <Image
src={`/images/img-sequence/${scrolled
.toString()
.padStart(4, '0')}.webp`}
layout="fill"
className="img-sequence"
priority={true}
quality={1}
alt="img sequence"
/> */}
<img
src={`./images/img-sequence/${scrolled
.toString()
.padStart(4, '0')}.webp`}
className="img-sequence"
/>
</div>
</div>
</>
);
}
Does anyone have an idea whats the issue?