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

137
Views
Carousel in React

i made a carousel, but i'm having a hard time with the animation. I want it to slide from the right if i click the right button, and from the left if i click the left button. So what i did was create a state const [classactive, setClassactive] = useState(false); and said that the img class is className={classactive == true ? "active-right" : "active-right-2"}. I did that in order to keep the animation happening. The classes are exactly the same on CSS. So, with the left button, i thought of doing the same but instead of using a class, using a ID, and it did work, the problem is that the right slide animation stoped. I feel like i'm making it more complicated than it really is. The img is an array with each picture's src.

<div className="thumb">
          <img
            src={img[index]}
            width="700px"
            className={classactive == true ? "active-right" : "active-right-2"}
            id={idactive == true ? "active-left" : "active-left-2"}
            name="thumbs"
          ></img>
          <div className="label">
            <h1>{projectTitle[index]}</h1>
            <p>{projectDesc[index]}</p>
          </div>
        </div>
about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

The issue is that ID selectors have a higher specificity than classes, so once your img element has an active ID, the css rules related to that ID will over-rule the classes css.

One approach would be to change the classactive state value to be a string representing a variable classname instead of a boolean value, and have the click handler determine that name. This way you don't need any ID's just a single stateful classname.

Following this line of thinking can get quite messy but it's not the most complicated solution. Good luck ๐Ÿ‘

about 4 years ago ยท Juan Pablo Isaza 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!