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

259
Views
how to control the slide direction when sliding the last item to the first item?

Here is my code:

import React,{ useState } from 'react';
import { Button, Card, Carousel } from 'react-bootstrap';

export default function L() {
    const [index, setIndex] = useState(0);
    let updateIndex = () => {
        let temp;
        if (index === 2) {
            temp = 0;
        } else {
            temp = index + 1;
        }
        setIndex(temp);
    }
    return (
        <Card className="p-1 vh-100 vw-100" variant="dark">
            <Card.Header className="border border-dark d-flex flex-row justify-content-center mb-1 rounded-3">
            Header
           </Card.Header>
            <Card.Body className="border border-dark d-flex flex-grow-1 m-0 p-1 rounded-3">
                <Carousel
                    activeIndex={index}
                    className="d-flex flex-grow-1 m-0 p-0 rounded-3"
                    controls={false}
                    interval={10000}
                    indicators={false}
                    nextIcon={null} nextLabel={null}
                    prevIcon={null} prevLabel={null}>
                    <Carousel.Item className="border border-dark h-100 m-0 p-0 rounded-3">
                        1
                    </Carousel.Item>
                    <Carousel.Item className="border border-dark h-100 m-0 p-0 rounded-3">
                        2
                    </Carousel.Item>
                    <Carousel.Item className="border border-dark h-100 m-0 p-0 rounded-3">
                        3
                    </Carousel.Item>
                </Carousel>
            </Card.Body>
            <Card.Footer className="border border-dark d-flex flex-row justify-content-around mt-1 rounded-3">
                <Button onClick={updateIndex}>Go</Button>
            </Card.Footer>
        </Card>
    )
}

The code works fine except when sliding from the last carousel item to the first carousel item. When sliding from the first item to the second item, the sliding direction is right to left. However, when sliding from the last item from the first item, the sliding direction is left to right. Is it possible to unify the sliding direction whatever any item transitions?

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!