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

251
Visualizações
Slideshow transitions stop working after the first slide

I am creating a slider where when I press the prev or next button the image should enter with a transition effect. The issue is that the transition works only when the page first loads and does not work after the first render. I need the transitions to work on each click and the transitions are applied to the section element class. If anyone know the solution please help me.

const SlideShowTop = (props) => {
  const [selectedIndex, setSelectedIndex] = useState(0);

  const previous = () => {
    if (selectedIndex !== 0) {
      setSelectedIndex((index) => index - 1);
    }
    if (selectedIndex === 0) {
      setSelectedIndex(props.slides.length - 1);
    }
  };

  const next = () => {
    if (selectedIndex !== props.slides.length - 1) {
      setSelectedIndex((index) => index + 1);
    }
    if (selectedIndex === props.slides.length - 1) {
      setSelectedIndex(0);
    }
  };

  const filteredSlide = props.slides.filter((data) => {
    return data.index === selectedIndex;
  });

  const sliderList = filteredSlide.map((slideProp, index) => {
    const getImg = require("../assets/" + slideProp.picture).default;
    return (
      <section className={classes.transitions}>
//to this section applying the transition

        <li
          className={`${[classes.banner]} `}
          style={{
            backgroundImage: `url(${getImg})`,
          }}
        >
          <div className={classes.banner__contents}>
            <h1 className={classes.banner__title}>
              {props.slides[selectedIndex].title}
            </h1>
            <div className={classes["ty-seqHomeSlider-nav"]}>
              <button
                onClick={previous}
                type="button"
                class={classes["seq-prev"]}
              >
                <i
                  className="fa fa-angle-left"
                  style={{ color: "white" }}
                  aria-hidden="true"
                ></i>
              </button>
              <button onClick={next} type="button" class={classes["seq-next"]}>
                <i
                  className="fa fa-angle-right"
                  style={{ color: "white" }}
                  aria-hidden="true"
                ></i>
              </button>
            </div>
            <h1 className={classes.banner__description}>
              {props.slides[selectedIndex].overview}
            </h1>
          </div>
          <div className={classes.banner_fadeBottom}></div>
        </li>
      </section>
    );
  });

  return (
    <div>
      <ul>{sliderList}</ul>
    </div>
  );
};

export default SlideShowTop;

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Can you provide a repro on code sandbox would be easy. If I look into this code now, it is only return you one slide. so, sliderList is created with only one slide.

const filteredSlide = props.slides.filter((data) => {
    return data.index === selectedIndex;
});
over 4 years ago · Santiago Trujillo Relatório

0

your question does not contain enough informations to solve your problem, however I see that you are using a CSS animation injected with react-jss, and that you only have a single slide per time.

I think that your problem is related to CSS animations, so the answer is probably available at this link --> JavaScript CSS animation only works once.

over 4 years ago · Santiago Trujillo Relatório
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