I am currently developing a canvas whiteboard tool and I have reached the stage where I am focusing on implementing the Zoom In and Zoom Out feature.
While the functionality is working fine, I would like to enhance it with smooth animations for scaling. However, the current scaling happens too quickly that the effect is not noticeable. Whenever I click on the + or - button, the scaling occurs instantly.
let scaleAmount = 1.00;
function scaleUpdate()
{
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.scale(scaleAmount, scaleAmount)
scaleSize.innerText = parseInt(parseFloat(scaleAmount.toFixed(2))*100)+"%";
stageUpdate();
}
function scale(direction)
{
let scaleSize = document.getElementById("scaleSize");
if(direction=="zoomIn")
{
for(let i = 0; i<10; i++)
{
scaleAmount += 0.01;
scaleAmount = parseFloat(scaleAmount.toFixed(2));
dx += scaleAmount;
dy += scaleAmount;
scaleUpdate();
}
}
if(direction=="zoomOut")
{
for(let i = 0; i<10; i++)
{
scaleAmount -=0.01;
scaleAmount = parseFloat(scaleAmount.toFixed(2));
dx -= scaleAmount;
dy -= scaleAmount;
scaleUpdate();
}
}
}
dx and dy represent screen offsets.
Can anyone assist me in addressing this issue?
Thank you, Frank