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

203
Visualizações
How to drag a component with animation in React

I am trying to drag a component whose css has transform animation. But it could not work. The component just move according to animation and could not be dragged. Is there any way to achieve the drag function?

import * as React from "react";
import {
  theComponent
} from "../style.css";
import Draggable from "react-draggable";

class DragMe extends React.Component {
  render() {
    return (
      <Draggable
        axis="both"
        handle=".handle"
        defaultPosition={{ x: 0, y: 0 }}
        position={null}
        grid={[25, 25]}
        scale={1}
        onStart={this.handleStart}
        onDrag={this.handleDrag}
        onStop={this.handleStop}
      >
        <div className={theComponent + " handle"}>
          <p>Drag Me!</p>
        </div>
      </Draggable>
    );
  }
}
. theComponent{
  animation: moveAnimation 3.5s infinite;
}

@keyframes moveAnimation {
  0%,
  100% {
    transform: translate(-200%, 20%);
  }
  50% {
    transform: translate(-200%, 25%);
  }
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you change css animation from transform to top, left, inline styles transform will be work and dragged. Try rewrite css like this example

.theComponent {
  position: relative;
  animation: moveAnimation 3.5s infinite;
}
@keyframes moveAnimation {
  0%,
  100% {
    top: 5px;
  }
  50% {
     top: 0px;
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
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