Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
How do you get an automatic slideshow in javascript to show images?

I'm pretty new to javascript, and I'm trying to create an automatic slideshow/carousel that displays images. I came across how to create an automatic slide show where each slide is a color, but I'm struggling to get it to display an image. Below, I have included what I have so far. I would really appreciate any help or advice on how to get this to work.


import React, {useState, useEffect} from 'react';
import C1 from './CarouselData';
//import {image} from './CarouselData';
//importBackIosIcon from @material-ui/icons/ArrowBackIos'//

const image = ["C1", "#00C49F", "#FFBB28"];
const delay = 3000;

export default function Carousel () {
  const [index, setIndex] = React.useState(0);
  const timeoutRef = React.useRef(null);

  function resetTimeout() {
    if (timeoutRef.current) {
      clearTimeout(timeoutRef.current);
    }
  }

  React.useEffect(() => {
    resetTimeout();
    timeoutRef.current = setTimeout(
      () =>
        setIndex((prevIndex) =>
          prevIndex === image.length - 1 ? 0 : prevIndex + 1
        ),
      delay
    );
  
  return () => {
      resetTimeout();
    };
  }, [index]);

  return (
    <div className="slideshow">
      <div
        className="slideshowSlider"
        style={{ transform: `translate3d(${-index * 100}%, 0, 0)` }}
      >
        {image.map((background, index) => (
          <div
            className="slide"
            key={index}
            style={{ background}}
          ></div>
        ))}
        </div>

      <div className="slideshowDots">
        {image.map((_, idx) => (
          <div
            key={idx}
            className={`slideshowDot${index === idx ? " active" : ""}`}
            onClick={() => {
              setIndex(idx);
            }}
          ></div>
        ))}
      </div>
    </div>
   
  );
}

CarouselData.js


import C1 from '../carousel-images/carousel-1.jpg';
import C2 from '../carousel-images/carousel-2.jpg';
import C3 from '../carousel-images/carousel-3.jpg';

export const image = [C1, C2, C3];

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda