25 lines
578 B
HTML
25 lines
578 B
HTML
<style>
|
|
canvas {
|
|
width: 100px;
|
|
height: 100px;
|
|
}
|
|
</style>
|
|
<body>
|
|
<canvas id="canvas1"></canvas>
|
|
<canvas id="canvas2"></canvas>
|
|
<script>
|
|
function drawRect(id) {
|
|
const canvas = document.getElementById(id);
|
|
canvas.width = canvas.clientWidth;
|
|
canvas.height = canvas.clientHeight;
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
ctx.fillStyle = 'green';
|
|
ctx.fillRect(0, 0, 100, 100);
|
|
}
|
|
|
|
drawRect('canvas1');
|
|
drawRect('canvas2');
|
|
</script>
|
|
</body>
|