canvas绘制时钟
var dom=document.getElementById("clock");//获取canvas的id
var ctx=dom.getContext("2d");//获取上下文,HTML5不支持3d
var width=ctx.canvas.width;//
var height=ctx.canvas.height;
var r=width/2;
//定义一个方法画圆
function drawBackground(){
ctx.save();
//转换坐标
ctx.translate(r,r);
ctx.lineWidth=10;
//获取路径
ctx.beginPath();
//画圆
ctx.arc(0,0,r-5,0,2*Math.PI,false);
//绘制当前路径
ctx.stroke();
}
//执行方法
drawBackground();
代码如上,但是出来如下图,,,不解,,,有大神可以给解释一下吗??头一次学习canvas
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
canvas那儿改成这样子
https://developer.mozilla.org...
use
<canvas width="300" height="300" id="clock"></canvas>to specify the physical size of the canvasor `dom.width=200;
dom.height=200;`
and don't call it 'dom', it is a canvas element.