问答详情
源自:3-3 Canvas静态的时分秒

哪位大神可以帮帮我吗


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>canvas时钟</title>

<style type="text/css">

#clock{

border: 2px solid red;

}

div{

text-align: center;

margin-top: 250px;

}

</style>

</head>

<body>

<div>

<p>时钟</p>

<canvas id="clock2" height="300px " width="200px"></canvas>

</div>

<script type="text/javascript" >

var don=document.getElementByID("clock2");

var cxt=dom.getContext('2d');

var height=cxt.canvas.height;

var width=cxt.canvas.width;

var r=width/2;


function drawBackground()

{

cxt.translate(r,r);

cxt.beginPath();

cxt.lineWidth=10;

cxt.arc(0,0,r-5,0,2*Math.PI,false);

cxt.stroke();


var hourNumbers=[3,4,5,6,7,,8,9,10,11,12,1,2];

cxt.textAlign='center';

cxt.textBaseline='middle';

hourNumbers.forEach(function(number,i){

var rad=2*Math.PI/12

*i;

var x=Math.cos(rad)*(r-30);

var y=Math.sin(rad)*(r-30);

});


for (var i = 0; i <60; i++) {

var rad=2*Math.PI/60*i;

var x=Math.cos(rad)*(r-18);

var y=Math.sin(rad)*(r-18);

cxt.beginPath();

if (i%5==0) {

cxt.fillStyle='#000';

cxt.arc(x,y,2,0,2*Math.PI,false);

} else {

cxt.fillStyle='#ccc';

cxt.arc(x,y,2,0,2*Math.PI,false);

}

ctxfill();

}

}

drawBackground();

</script>

</div>

</body>

</html>


提问者:qq_陌若安生_8 2017-05-13 11:06

个回答

  • Ellision
    2017-05-17 18:21:25
    已采纳

    1、原代码:var don=document.getElementByID("clock2"); 修改后:var dom = document.getElementById("clock2");

    2、原代码:ctxfill();;修改后:cxt.fill();

  • 慕数据6363475
    2018-06-05 14:49:48

    “cxt”⇒“ctx”

  • qq_陌若安生_8
    2017-05-27 09:20:12

    你运行了可以吗,我改了还是不行呢