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

219
Visualizações
How to differentiate between mousedown and mousedrag

I am performing some actions on onMousedown event. But then they also get executed for drag as drag starts with mouse down.

How can I ensure that actions on mouse-down don't happen for mouse drag?

Note: I am using scalajs-react, though that must not matter.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Mouse drag events trigger an event of DragEvent type, mouse down triggers only MouseEvent. You can differentiate both, by validating dataTransfer attribute, which is only present in DragEvent, like this:

function functionTriggeredOnMouseDownAndDrag(evt) {
    if (typeof evt.dataTransfer !== 'undefined') {
        // code for mouse drag
    } else {
        // code for other mouse events
    }
}

element.addEventListener('mousedown', functionTriggeredOnMouseDownAndDrag)
element.addEventListener('mousemove', functionTriggeredOnMouseDownAndDrag)
about 4 years ago · Santiago Gelvez 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