Home > Web Front-end > HTML Tutorial > Zoom HTML5 canvas to mouse cursor

Zoom HTML5 canvas to mouse cursor

PHPz
Release: 2023-09-19 12:49:02
forward
872 people have browsed it

Zoom HTML5 canvas to mouse cursor

The canvas is always scaled from the current origin. The default origin is [0,0]. If you want to zoom from another point, you can first do ctx.translate(desiredX,desiredY); . This will reset the canvas's origin to [desiredX,desiredY].

The translate() method remaps the (0,0) position on the canvas. The scale() method enlarges or reduces the current graphic. If you want to pan() the canvas context by an offset, you need to first scale() it to zoom in or out, and then pan() it by the opposite position of the mouse offset.

These following examples give the steps

ctx.translate(pt.x,pt.y);
ctx.scale(factor,factor);
ctx.translate(-pt.x,-pt.y);
Copy after login

The above is the detailed content of Zoom HTML5 canvas to mouse cursor. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template