Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

254
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda