キャンバスの内部に線を描くと、その線が動的に作成されます。行末に、私はHTMLボタンを作成したいと思います。しかし、私は作成する方法を知らない。 Plz、助けてください。HTML内に動的にボタンを配置<canvas>
HTML
<canvas id="c"></canvas>
<input id="btn" type="button">
Javascriptを
var line = document.createElement("canvas");
var ctx = line.getContext("2d");
document.getElementById("c").style.height = "300px";
ctx.fillStyle = "red";
ctx.fillRect(10, 1, line.width, line.height);
var ctx = c.getContext("2d");
drawLine(20, 20, 150, 70);
function drawLine(x1, y1, x2, y2) {
var dx = x2 - x1,
dy = y2 - y1,
len = (Math.sqrt(dx*dx+dy*dy)-1)|0,
ang = Math.atan2(dy, dx);
ctx.translate(x1|0, y1|0);
ctx.rotate(ang);
ctx.drawImage(line, 0, 0, len, 1);
ctx.setTransform(1,0,0,1,0,0)
}
ctx.arc(20, 20, 5, 0, 2 * Math.PI);
ctx.fillStyle = 'green';
ctx.fill();
ctx.strokeStyle = 'red'
ctx.stroke();
ボタンをキャンバスの上に浮かべてください。 – theonlygusti
また、スタイリングでキャンバスのサイズを変更しないでください。 – theonlygusti
なぜ '|'を使用していますか? – theonlygusti