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

193
Visualizações
How to override mouse event with touch event using javascript?

I'm trying to simulate the touch events in a react.js application. The goal is to trigger touch events instead of mouse ones (i.e. mouseDown should trigger touchStart, etc.).

The behavior I'm trying to replicate is the same one as when you're using the Chrome dev tool console on mobile view.

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

0

You can create an event with the class Event. Then you can dispatch the event on a dom element or on window

const clickEvent = new Event('touchStart', {"bubbles":true})
window.dispatchEvent(clickEvent);

Here is a long article that covers these 2 lines of code: https://medium.com/@gianfranconuschese/simulating-events-with-javascript-c62da15422b2

so basically you could use window.addEventListener('mouseDown', eventHandler) where eventHandler would be a function that calls the two lines of code I shared earlier

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