教程集 www.jiaochengji.com
教程集 >  前端编程  >  HTML5教程  >  正文 用html5实现一个简单的钟表外观

用html5实现一个简单的钟表外观

发布时间:2020-07-24   编辑:jiaochengji.com
教程集为您提供用html5实现一个简单的钟表外观等资源,欢迎您收藏本站,我们将为您提供最新的用html5实现一个简单的钟表外观资源
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实现一个简单的钟表外观的详细内容,更多请关注教程集其它相关文章!

-->
  • 本文原创发布教程集,转载请注明出处,感谢您的尊重!
  • 您可能感兴趣的文章:
    用html5实现一个简单的钟表外观
    html5 main标签是什么意思?html5 main标签作用的详细介绍
    h5中main元素的实例详解
    html5是什么?html5的介绍以及优缺点总结
    HTML5 video 实现浏览器兼容的方法
    关于HTML5中video标签浏览器兼容性增强的方案分享
    html5全新的网络格局
    浅谈HTML5的未来发展
    前端html5框架有哪些?html5常见六大框架
    零基础学习HTML5

    [关闭]
    ~ ~