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

135
Views
css transition is not making a smooth transition from left to right

I'm trying to make an image carousel, and im having issues with getting the slider to move smoothly from the left to right.

I'm trying to achieve a similar slide effect to this, without the dots and all. Just the simple slide effect.

below

https://stackblitz.com/edit/reactcarousel?file=Carousel.js

here is my the current css

style.css

h1,
p {
  font-family: Lato;
}

.wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  flex-direction: row;
  overflow: hidden;
}
.box {
  width: 100%;
  padding: 20px;
  overflow: hidden;
}

button {
  height: 40px;
}
.slide {
  width: 100%;
  transform: translateX(-100%);
  background-color: red;
  transition: all 0.43s ease-in;
}
.slide-active {
  width: 100%;
  transform: translateX(0%);
  transition: all 0.43s ease-in;
}

Carousel.js

import React from 'react';
import '../style.css';
export function Carousel({ children, activeSlide, setActiveSlide }) {
  const nextSlide = () => {
    const slides = React.Children.toArray(children);
    if (activeSlide === slides.length - 1) {
      console.log('dsfsfsf');
      setActiveSlide(activeSlide);
    } else {
      setActiveSlide(activeSlide === slides.length - 1 ? 0 : activeSlide + 1);
    }
  };
  const prevSlide = () => {
    if (activeSlide === 0) {
      setActiveSlide(activeSlide);
    } else {
      setActiveSlide(activeSlide - 1);
    }
  };
  return (
    <div class="wrapper">
      <button onClick={prevSlide}>Prev</button>
      <div className="box">
        {React.Children.map(
          children,
          (slide, index) =>
            index === activeSlide && (
              <div className={index === activeSlide ? 'slide-active' : 'slide'}>
                {slide}
              </div>
            )
        )}
      </div>
      <button onClick={nextSlide}>Next</button>
    </div>
  );
}

Demo

https://stackblitz.com/edit/react-ueuthh?file=src%2FCarousel%2FCarousel.jsx

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