<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.success{
display: inline-block;
font-weight: 700;
margin: 0 10px;
width: 8px;
height: 13px;
transform: rotate(45deg);
border-style: solid;
border-color: #009933;
border-width: 0 4px 4px 0 ;
}
.error {
width: 15px;
height: 15px;
margin: auto;
position: relative;
margin-left: 32px;
}
.error::before,
.error::after {
content: "";
position: absolute;
height: 18px;
width: 3px;
top: 0px;
right: 15px;
background: red;
}
.error::before {
transform: rotate(45deg);
}
.error::after {
transform: rotate(-45deg);
}
</style>
</head>
<body>
<div class="success"></div>
<br/>
<div style="float:left;" class="error"></div>
<canvas id="success" style="border: 1px solid red;"></canvas>
<canvas id="error" style="border: 1px solid red;"></canvas>
<script>
window.onload=function(){
var canvasSreen = document.getElementById('success');
canvasSreen.width = 50;
canvasSreen.height = 50;
//当浏览器不支持canvas的时候,另一种提示方式
if (canvasSreen.getContext('2d')) {
var context = canvasSreen.getContext('2d');
//使用context绘制
}else{
alert('当前浏览器不支持canvas,请更换浏览器后再试');
}
context.beginPath();//开始路径状态
context.moveTo(5,20);//笔尖落在哪
context.lineTo(20,35);//笔尖走到哪
context.lineTo(45,10);//笔尖落在哪
context.lineWidth = 5;//笔水的大小
context.strokeStyle = "red"; //笔的颜色
context.stroke();//绘制
var canvasError = document.getElementById('error');
canvasError.width = 50;
canvasError.height = 50;
if (canvasError.getContext('2d')) {
var ctx = canvasError.getContext('2d');
//使用context绘制
}else{
alert('当前浏览器不支持canvas,请更换浏览器后再试');
}
ctx.beginPath();//开始路径状态
ctx.moveTo(10,10);//笔尖落在哪
ctx.lineTo(40,40);//笔尖走到哪
ctx.lineWidth = 5;//笔水的大小
ctx.strokeStyle = "red"; //笔的颜色
ctx.stroke();//绘制
ctx.beginPath();//开始路径状态
ctx.moveTo(40,10);//笔尖落在哪
ctx.lineTo(10,40);//笔尖走到哪
ctx.lineWidth = 5;//笔水的大小
ctx.strokeStyle = "red"; //笔的颜色
ctx.stroke();//绘制
}
</script>
</body>
</html>