Skip to content
Advertisement

Canvas zoom to cursor doesn’t work correct

I’m trying to scale canvas to/from mouse position, but it works not perfect (always goes few cells away from mouse pos). I’ve read all similar posts but i don’t know what’s wrong.

https://jsfiddle.net/shumikua/3afxtmqw/

All code is only to run snippet, it works good. Problem is in function scale.

JavaScript

Advertisement

Answer

In function scale() keep the same values for x and y before and after scaling. You just need to update coordinates in screen panX and panY.

JavaScript
JavaScript
JavaScript

Hold Ctrl and scroll wheel to scale.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement