Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda