SagRU
SagRU

Reputation: 448

How to reset HTML5 canvas after zooming?

I'm trying to create an HTML5-canvas based web app with zooming-to-cursor functionality. 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.

Live code: https://jsfiddle.net/Arkonage/tgkv21s8/22/

Upvotes: 0

Views: 602

Answers (1)

Ouroborus
Ouroborus

Reputation: 16875

As a quick and dirty solution:

  • Add ctx.save(); to the beginning of the trackTransforms() function definition.
  • Add ctx.restore(); ctx.save(); to the beginning of the resetCanvas() function definition.

Upvotes: 1

Related Questions