Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!