コード私はランダムな四角形を生成したいキャンバスを持っています。私はちょうど私が幅、高さ、矩形の色を変更する方法を把握しようとしていることが
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script>
window.onload {
function rectWidth() {
var width = document.getElementById('Canvas').offsetWidth;
Math.floor((Math.random() * 100) + 1);
}
function rectHeight() {
var width = document.getElementById('Canvas').offsetHeight;
Math.floor((Math.random() * 200) + 2);
}
function randColor() {
var randomColor = Math.floor(Math.random()*16777215).toString(16);
}
return rectWidth;
return rectHeight;
return randColor;
$(#rect).html("<rect width="return rectWidth;" height="return rectHeight" style=""color="return randColor"/>")}
}
</script>
</head>
<body>
<canvas id="Canvas" width="900" height="200">
<rect id="rect" width="250" height="250" style="color=blue"/></canvas>
を動作させるように見えることはできません。
次にポジションが来ます。
コードを変更して動作させるにはどうすればよいですか?キャンバス上に四角形を描画する方法の
キャンバス上に描画する方法ではありません。キャンバスにhtmlを使って長方形を描画することはできません。それはjavascriptで行う必要があります。 –
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/rect –
試しました。まだ動作しません。 http://codepen.io/PCMRwill0956/pen/LRNyyJ – will0956