Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

E-commerce using Next.JS

Josh Michael 1,050

@joshmichael23

Desktop design screenshot for the E-commerce product page coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
3intermediate
View challenge

Design comparison


SolutionDesign

Solution retrospective


I am having a layout shift sometimes when loading the images. Could this be related to Images component? Thanks in advance.

Community feedback

P

@cancomertpay

Posted

Hi Josh,

You can try more basic carousel logic like this:

...

const [currentImgIndex, setCurrentImgIndex] = useState(0);

  const nextImage = () => {
    if (currentImgIndex < images.length - 1) {
      setCurrentImgIndex((prev) => prev + 1);
    } else {
      setCurrentImgIndex(0);
    }
  };

  const prevImage = () => {
    setCurrentImgIndex((prev) => prev - 1);
    if (currentImgIndex === 0) {
      setCurrentImgIndex(images.length - 1);
    }
  };

  const handleThumbnailClick = (index) => {
    setCurrentImgIndex(index);
  };

...

    return images.map((item,index) => (
    <div
      style={{
        opacity: index === currentImgIndex ? 1 : 0,
        transition: "opacity 1s ease",
        width: index === currentImgIndex ? "100%" : "auto",
      }}
    >
      <img
        src={item}
        alt={"..."}
      />
    </div>
))

This was just an example to explain the logic, I hope it helped. :)

Marked as helpful

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord