复制代码代码如下: !DOCTYPE html html head meta charset="UTF-8" title HTML CLOCK /title /head body canvas width="500" height="500" id="clock" 你的浏览器不支持canvas标签,时针显示不出来哦! /canvas
script type="text/javascript" //画布背景颜色 var clockBackGroundColor = "#ABCDEF"; //时针颜色 var hourPointColor = "#000"; //时针粗细 var hourPointWidth = 7; //时针长度 var hourPointLength = 100; //分针颜色 var minPointColor = "#000"; //分针粗细 var minPointWidth = 5; //分针长度 var minPointLength = 150; //秒针颜色 var secPointColor = "#F00"; //秒针粗细 var secPointWidth = 3; //秒针长度 var secPointLength = 170; //表盘颜色 var clockPanelColor = "#ABCDEF"; //表盘刻度颜色 var scaleColor = "#000"; //表盘大刻度宽度 3 6 9 12 var scaleBigWidth = 9; //表盘大刻度的长度 var scaleBigLength = 15; //表盘小刻度的宽度 var scaleSmallWidth = 5; //表盘小刻度的长度 var scaleSmallLength = 10; //圆心颜色 var centerColor = 'red';
//时钟画布 var clock = document.getElementById('clock'); clock.style.background = clockBackGroundColor; //时针画布的作图环境(画板) var panel = clock.getContext('2d');
panel.fillText("",10,20); panel.fillText(" a href="http://www.phpstudy.net",10,40" http://www.phpstudy.net",10,40 /a var date = new Date(); var sec = date.getSeconds(); var min = date.getMinutes(); var hour = date.getHours() + min/60; drowCircle(panel,7,'blue',250,250,200); drowScales(panel);