html5已经出来好长时间了,但仍然有不多小伙伴们不太懂,下面小编就来用html5实现一个简单的钟表外观
<html lang="en-us">
<style>
#mycanvas{border:3px solid blue;}
</style>
<head>
<script type="text/javascript">
window.onload = function()
{
var mycanvas = document.getelementbyid("mycanvas");
var context = mycanvas.getcontext("2d");
context.linewidth = 2;
context.strokestyle = "blue";
context.fillstyle = "blue";
context.arc(250,200,5,0,math.pi*2,true);
context.fill();
context.beginpath();
context.arc(250,200,150,0,math.pi*2,true);
context.stroke();
context.translate(250,200);
context.rotate(-math.pi/2);
context.save();
for(var i=0;i<60;i++)
{
if(i % 5 == 0)
{
context.fillrect(130,0,20,5);
context.filltext((i/5 == 0?12:i/5),120,5);
}
else
{
context.fillrect(140,0,10,2)
}
context.rotate(math.pi/30); //360°每6度旋转一次
}
context.fillrect(0,-2,90,3);
context.stroke();
}
</script>
</head>
<body>
<canvas id=mycanvas width=500px height=400px></canvas>
</body>
</html>
效果图
以上就是用html5实现一个简单的钟表外观的详细内容。