<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 demo</title>
<style>
.clock {
width: 600px;
height: 600px;
border: 2px dotted red;
border-radius: 20px;
background: url('clockface.jpg') no-repeat;
}
</style>
</head>
<body>
<div class="clock">
<canvas id="canvas" width="600" height="600">Not supported</canvas>
</div>
</body>
<script type="text/javascript">
startClock();
function $(id) {
return document.getElementById(id);
}
function startClock() {
setInterval("drawClock()", 1000);
}
function computePostions() {
var time = new Date();
var ss = time.getSeconds() / 60;
var mm = (time.getMinutes() + ss) / 60;
var hh = (time.getHours() + mm) / 12;
return {
'h': (hh * 2 + 1) * Math.PI,
'm': (mm * 2 + 1) * Math.PI,
's': (ss * 2 + 1) * Math.PI
};
}
function drawClock() {
var pos = computePostions();
var ctx = $('canvas').getContext('2d');
ctx.clearRect(0, 0, 600, 600);
// hour
ctx.save();
ctx.beginPath();
ctx.translate(300, 300);
ctx.rotate(pos.h);
ctx.strokeStyle = "#FBD10B";
ctx.fillStyle = "#FBD10B";
ctx.lineWidth = "3";
ctx.moveTo(-4, 0);
ctx.lineTo(0, 80);
ctx.lineTo(4, 0);
ctx.lineTo(-4, 0);
ctx.fill();
ctx.stroke();
ctx.closePath();
ctx.restore();
// minute
ctx.save();
ctx.beginPath();
ctx.translate(300, 300);
ctx.rotate(pos.m);
ctx.strokeStyle = "#4CB549";
ctx.fillStyle = "#4CB549";
ctx.lineWidth = "2";
ctx.moveTo(-3, 0);
ctx.lineTo(0, 120);
ctx.lineTo(3, 0);
ctx.lineTo(-3, 0);
ctx.fill();
ctx.stroke();
ctx.closePath();
ctx.restore();
// second
ctx.save();
ctx.beginPath();
ctx.translate(300, 300);
ctx.rotate(pos.s);
ctx.strokeStyle = "#CB0909";
ctx.fillStyle = "#CB0909";
ctx.lineWidth = "1";
ctx.moveTo(0, 0);
ctx.lineTo(0, 180);
ctx.lineTo(0, 0);
ctx.arc(0, 0, 10, 0, Math.PI * 2, true);
ctx.fill();
ctx.stroke();
ctx.closePath();
ctx.restore();
}
</script>
</html>
分享到:
相关推荐
HTML5 Canvas创意时钟特效是一款基于HTML5和Canvas绘制的圆形个性化时钟动画特效。
HTML5 canvas数字时钟15种样式代码,网页走动时钟。
html5 canvas云粒子数字时钟动画特效 html5 canvas云粒子数字时钟动画特效
javascript HTML5 canvas 时钟
使用html5中的canvas标签+jquery绘制的时钟走动代码
使用html5中的canvas,结合javascript实现时钟效果
html5 canvas制作15种数字时钟样式代码 html5 canvas制作15种数字时钟样式代码
用HTML5的Canvas制作的时钟显示效果,绘制了表盘,时针,分针,秒针以及数字时间的显示,对该文件有问题可以私聊
html5 canvas画布绘制圆形时钟代码
NULL 博文链接:https://mooring.iteye.com/blog/1594032
html5 canvas圆形时钟代码是一款采用canvas画布实现的本地时钟代码下载。
之前我们有给大家介绍过很多基于...这次要分享的是15个超绚丽的HTML5 Canvas时钟动画特效,它们很多都有各自不同的外观,有几个时钟的造型还非常新颖奇特,因为是基于HTML5 Canvas的,所以你的浏览器需要支持HTML5。
HTML5 canvas超逼真的模拟时钟特效 canvas
html5 canvas扁平网页时钟代码 html5 canvas扁平网页时钟代码 html5 canvas扁平网页时钟代码 html5 canvas扁平网页时钟代码
HTML5 Canvas爱心时钟代码.zip
thooClock是一款效果非常逼真的HTML5 canvas模拟时钟特效。该时钟特效使用jQuery和HTML5 Canvas API来制作,模拟现实生活中的时钟。并且它还具有定时闹钟的功能。掩饰地址:http://www.jq22.com/jquery-info3928