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

272
Visualizações
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 à 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