先生成画布:
<canvas class="can" width="500px" height="500px"></canvas>
调画布样式:
.can{
border: 1px solid;
display: block;
margin: auto;
}
JS部分:
var can = document.getElementsByClassName("can")[0];
var cantxt = can.getContext("2d");
function fun(){
//保存当前绘图
cantxt.save();
//表盘
cantxt.translate(250,250)
cantxt.beginPath();
cantxt.lineWidth = 10;
cantxt.arc(0,0,245,0,Math.PI*2)
cantxt.stroke();
cantxt.closePath();
//数字
var num = [3,4,5,6,7,8,9,10,11,12,1,2];
cantxt.textAlign = 'center';
cantxt.textBaseline = "middle";
cantxt.font = "20px Arial";