[英]How to reset HTML5 canvas after zooming?
I'm trying to create an HTML5-canvas based web app with zooming-to-cursor functionality.我正在尝试创建一个基于 HTML5 画布的 web 应用程序,它具有缩放到光标功能。 The idea is simple:这个想法很简单:
I'm having troubles with the last step.我在最后一步遇到了麻烦。 When I load the first image, zoom in/out and then load the second image, I get the second image already zoomed to the scale of the previous image.当我加载第一张图片,放大/缩小然后加载第二张图片时,我得到的第二张图片已经缩放到前一张图片的比例。 I suppose the problem comes from trackTransforms
function (took it there ), but I don't understand how it works, so I can't track down the issue.我想问题出在trackTransforms
function(那里拿走了),但我不明白它是如何工作的,所以我无法找到问题所在。
Live code: https://jsfiddle.net/Arkonage/tgkv21s8/22/直播码: https://jsfiddle.net/Arkonage/tgkv21s8/22/
As a quick and dirty solution:作为一个快速而肮脏的解决方案:
ctx.save();
添加ctx.save();
to the beginning of the trackTransforms()
function definition.到trackTransforms()
function 定义的开头。ctx.restore(); ctx.save();
添加ctx.restore(); ctx.save();
ctx.restore(); ctx.save();
to the beginning of the resetCanvas()
function definition.到resetCanvas()
function 定义的开头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.