HTML5指针平缓转动圆形时钟特效代码

版权:原创 更新时间:1年以上
[该文章底部包含文件资源,可根据自己情况,决定是否下载资源使用,时间>金钱,如有需要,立即查看资源]

以下是 HTML5指针平缓转动圆形时钟特效代码 的示例演示效果:

当前平台(PC电脑)
  • 平台:

部分效果截图:

HTML5指针平缓转动圆形时钟特效代码

HTML代码(index.html):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HTML5指针平缓转动圆形时钟</title>
</head>
<body>
<div style="width:500px;margin:0 auto;">
	<canvas id="clock" width="500" height="500" onClick=resetcolor()>
		您的浏览器不支持canvas标签!
	</canvas>

</div>

<script>
	var clock=document.getElementById("clock");
	var cxt=clock.getContext("2d");
	var colr=(200+Math.floor(Math.random()*55.99));
	var colg=(200+Math.floor(Math.random()*55.99));
	var colb=(200+Math.floor(Math.random()*55.99));
	
	function resetcolor(){
		colr=(200+Math.floor(Math.random()*55.99));
		colg=(200+Math.floor(Math.random()*55.99));
		colb=(200+Math.floor(Math.random()*55.99));
	}
	
	function drawClock(){
	//获取时间
	var now=new Date();
	var hou=now.getHours();
	var min=now.getMinutes();
	var sec=now.getSeconds();
	var mec=now.getMilliseconds();
	
	//转换12小时进制
	hou=hou>12?hou-12:hou;
	//清空画布
	cxt.clearRect(0,0,500,500);
	//阴影
	cxt.fill();
	cxt.fillStyle="gray";
	cxt.beginPath();
	cxt.arc(270,260,205,0,Math.PI*2,true);
	cxt.closePath();
	cxt.fill();
	//表盘
	cxt.fill();
	cxt.fillStyle="white";
	cxt.beginPath();
	cxt.arc(250,250,205,0,Math.PI*2,true);
	cxt.closePath();
	cxt.fill();
	//蓝色表盘(边框)
	cxt.strokeStyle="#dddddd"
	cxt.lineWidth=10;
	cxt.beginPath();
	cxt.arc(250,250,185,0,Math.PI*2,true);
	cxt.closePath();
	cxt.stroke();
	cxt.strokeStyle="#"+colr.toString(16)+colg.toString(16)+colb.toString(16);
	cxt.lineWidth=10;
	cxt.beginPath();
	cxt.arc(250,250,200,0,Math.PI*2,true);
	cxt.closePath();
	cxt.stroke();
	cxt.strokeStyle="#"+colr.toString(16)+colg.toString(16)+colb.toString(16);
	cxt.lineWidth=3;
	cxt.beginPath();
	cxt.arc(250,250,192,0,Math.PI*2,true);
	cxt.closePath();
	cxt.stroke();
	cxt.strokeStyle="#"+(colr-100).toString(16)+(colg-100).toString(16)+(colb-100).toString(16);
	cxt.lineWidth=5;
	cxt.beginPath();
	cxt.arc(250,250,205,0,Math.PI*2,true);
	cxt.closePath();
	cxt.stroke();
	//刻度(时分)
		//时刻度
		for(var i=0;i<12;i++){
			cxt.save();
			cxt.lineWidth=5;
			cxt.strokeStyle="black";
			//设置原点
			cxt.translate(250,250);
			//设置旋转角度;
			cxt.rotate(30*i/180*Math.PI);
			cxt.beginPath();
			cxt.moveTo(0,180);
			cxt.lineTo(0,160);
			cxt.closePath();
			cxt.stroke();
			cxt.restore();
		}
		//分刻度
		for(var i=0;i<60;i++){
			if(i%5!=0){
				cxt.save();
				cxt.lineWidth=2;
				cxt.strokeStyle="black";
				//设置原点
				cxt.translate(250,250);
				//设置旋转角度;
				cxt.rotate(6*i/180*Math.PI);
				cxt.beginPath();
				cxt.moveTo(0,175);
				cxt.lineTo(0,165);
				cxt.closePath();
				cxt.stroke();
				cxt.restore();
			}
		}
	//指针(时分秒)
	//时针
	cxt.save();
	cxt.lineWidth=12;
	cxt.strokeStyle="black";
	cxt.beginPath();
	cxt.translate(250,250);
	cxt.rotate((hou*30+min*0.5+180)/180*Math.PI);
	cxt.moveTo(0,0);
	cxt.lineTo(0,90);
	cxt.closePath();
	cxt.stroke()
	cxt.restore();
	//分针
	cxt.save();
	cxt.lineWidth=5;
	cxt.strokeStyle="black";
	cxt.beginPath();
	cxt.translate(250,250);
	cxt.rotate((min*6+sec*0.1+180)/180*Math.PI);
	cxt.moveTo(0,0);
	cxt.lineTo(0,130);
	cxt.closePath();
	cxt.stroke()
	cxt.restore();
	//秒针
	cxt.save();
	cxt.lineWidth=2;
	cxt.strokeStyle="red";
	cxt.beginPath();
	cxt.translate(250,250);
	cxt.rotate((sec*6+mec*0.006+180)/180*Math.PI);
	cxt.moveTo(0,0);
	cxt.lineTo(0,150);
	cxt.closePath();
	cxt.stroke();
	cxt.fillStyle="red";
	cxt.beginPath();
	cxt.arc(0,148,4,0,Math.PI*2,true);
	cxt.closePath();
	cxt.fill();
	cxt.fillStyle="white";
	cxt.beginPath();
	cxt.arc(0,148,2,0,Math.PI*2,true);
	cxt.closePath();
	cxt.fill();
	cxt.restore();
	//秒针装饰
	cxt.fillStyle="red";
	cxt.beginPath();
	cxt.arc(250,250,15,0,Math.PI*2,true);
	cxt.closePath();
	cxt.fill();
	cxt.fillStyle="black";
	cxt.beginPath();
	cxt.arc(250,250,13,0,Math.PI*2,true);
	cxt.closePath();
	cxt.fill();
	cxt.fillStyle="white";
	cxt.beginPath();
	cxt.arc(250,250,10,0,Math.PI*2,true);
	cxt.closePath();
	cxt.fill();
	
}
drawClock();
//使用setInterval(代码,周期(毫秒制))让时钟动起来
setInterval(drawClock,10);
</script>
</body>
</html>











附件:下载该文件资源,减少时间成本(增值服务)
留言
该资源可下载
File Source
.rar
1.56 KB
Html 时钟特效
最新结算
HTML5 3D效果网页视频背景代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
软件概要设计说明书Word下载
类型: .docx 金额: CNY 0.38¥ 状态: 待结算 详细>
软件概要设计说明书Word下载
类型: .docx 金额: CNY 3.02¥ 状态: 待结算 详细>
.net c#获取声卡信息,声卡数量
类型: .rar 金额: CNY 30.96¥ 状态: 待结算 详细>
.net c#获取声卡信息,声卡数量
类型: .rar 金额: CNY 3.87¥ 状态: 待结算 详细>
.net c#获取电脑的安装软件列表信息,包含名称和版本号
类型: .rar 金额: CNY 30.96¥ 状态: 待结算 详细>
.net c#获取电脑的安装软件列表信息,包含名称和版本号
类型: .rar 金额: CNY 3.87¥ 状态: 待结算 详细>
.net c#获取电脑显示适配器信息
类型: .rar 金额: CNY 30.96¥ 状态: 待结算 详细>
.net c#获取电脑的安装软件列表信息,包含名称和版本号
类型: .rar 金额: CNY 3.87¥ 状态: 待结算 详细>
.net c#获取电脑的安装软件列表信息,包含名称和版本号
类型: .rar 金额: CNY 30.96¥ 状态: 待结算 详细>
各执行环节公正透明,帮助企业完成从赛制策划、活动推广、评委评选到版权转让等系列工作,专业、高效、值得信赖。平均每场赛事可征集到数百至数千组源码作品
合作伙伴
联系我们
  • 邮箱:raozetian@hotmail.com
Copyright 2023-2024 eeigg.com·皖ICP备2024038726号-1
打赏文章