画布
1、绘制矩形:
(1)使用原生的js,获取画布元素
(2)获取2d上下文对象
(3)设置绘图样式,绘制填充的矩形
context.fillStyle=“pink”;
(4)设置参数
context.fillRect(0,0.100,200);
(5)绘制边框矩形
context.lineWide=5;
(6)设置边框样式
context.strokeStyle=“red”;
(7)设置边框的长宽高
context.strokeRect();
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
canvas{
border: 1px solid red;
}
</style>
</head>
<body>
<canvas id="canvas" width="400px" height="400px"></canvas>
<script>
//使用原生js
window.onload=function(){
//获取画布元素
var canvas=document.getElementById("canvas");
//获取2d上下文对象
var context=canvas.getContext("2d");
//设置绘图样式
//绘制填充矩形
context.fillStyle="pink";
//参数 x,y,宽,高
context.fillRect(0,0,100,200);
//绘制边框矩形
context.lineWidth = 5
//设置边框样式
context.strokeStyle="skyblue"
context.strokeRect(100,100,100,100)
//绘制四个矩形拼接成一个大矩形
context.strokeStyle="blue"
context.strokeRect(205,100