Canvas制作:
需求:在画布四个角与中间位置画五个100*80的矩形,实心矩形要求颜色不同
<style>
body{
text-align:center;
}
canvas{
background-color:#ccc;
}
</style>
<body>
<h1>Canvas矩形</h1>
<canvas id="canvas" width="500" height="400"></canvas>
</body>
<script>
var canvas=document.getElementById('canvas');
var ctx=canvas.getContext('2d');
/*1.第一个左上角红色实心矩形*/
ctx.fillStyle="#f00";
ctx.fillRect(0,0,100,80);
/*2.第二个右上角绿色实心矩形*/
ctx.fillStyle="#0f0";
ctx.fillRect(400,0,100,80);
/*3.第三个右下角蓝色实心矩形*/
ctx.fillStyle="#00f";
ctx.fillRect(400,320,100,80);
/*4.第四个左下角黑色实心矩形*/
ctx.fillStyle="#000