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

271
Vistas
How to get correct mouse position when using pinch zoom using HTML and JS?

I have a simple HTML canvas element.

Using JavaScript I'm showing horizontal and vertical guidelines connecting under current mouse pointer position over canvas.

I was able to deal with Ctrl + + / - zoom using $window.devicePixelRatio, but now I face another problem.

When I pinch zoom on my Touch Pad, $window.devicePixelRatio is always "1", but suddenly my "crosshair" is off based on how big the zoom was.

When I click, I am not clicking where my mouse is, but the same bad position where "crosshair" is and when I move my mouse, there is some exponential movement of crosshair position (at the center of the canvas, mouse and crosshair are pretty much all right, but the more I move to one side, the bigger is the difference between "crosshair" and actual mouse position).

Everything is pretty much expected, since it was doing the same thing with Ctrl + + / - zoom before I fixed it.

My question: is there some way to translate "crosshair" position so it is actually always under the mouse pointer as well when using pinch zooming?

about 4 years ago · Juan Pablo Isaza
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