scrollwheel

Zoom Canvas to Mouse Cursor

你说的曾经没有我的故事 提交于 2019-11-25 23:48:59
问题 I\'m programming a HTML5 < canvas > project that involves zooming in and out of images using the scroll wheel. I want to zoom towards the cursor like google maps does but I\'m completely lost on how to calculate the movements. What I have: image x and y (top-left corner); image width and height; cursor x and y relative to the center of the canvas. 回答1: In short, you want to translate() the canvas context by your offset, scale() it to zoom in or out, and then translate() back by the opposite