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

194
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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