JSFiddle - React, Tailwind, and code Playground
HTML
<p><input type="number" id="scale" value="1" step=".1"></p>
<canvas width="500px" height="500px">Ваш браузер не поддерживает Canvas</canvas>
<!-- пример сайта know-online.com -->
CSS
body {
padding: 10px;
}
canvas {
border: 1px solid #ccc;
margin-top: 10px;
}
JavaScript
var canvas = document.querySelector("canvas"),
ctx = canvas.getContext("2d");
document.getElementById("scale").onchange = function(e) {
ctx.save();
ctx.clearRect(0, 0, 500, 500);
ctx.scale(this.value, this.value);
// 1. круг
ctx.beginPath();
ctx.arc(35, 35, 25, 0, Math.PI*2);
ctx.fillStyle = "#800";
ctx.closePath();
ctx.fill();
// 2. квадрат
ctx.beginPath();
ctx.rect(75, 10, 50, 50);
ctx.fillStyle = "green";
ctx.closePath();
ctx.fill();
// 3. квадрат без заливки
ctx.beginPath();
ctx.strokeStyle = "navy";
ctx.strokeRect(145, 10, 50, 50);
ctx.closePath();
ctx.fill();
ctx.restore();
}
document.getElementById("scale").onchange();