<!DOCTYPE html>
<html>
<head>
<title>Canvas</title>
</head>
<body>
<canvas id="canvas" width="1000" height="1000"></canvas>
<script type="text/javascript">
var currentSeconds = 10;
var countDownSeconds = 10;
var interval_id = setInterval("drawDoubleCircle()", 1000);
function drawDoubleCircle() {
if (currentSeconds <= 0) {
clearInterval(interval_id);
}
var canvasElement = document.getElementById('canvas');
var context = canvasElement.getContext('2d');
progress = 360 * currentSeconds / countDownSeconds;
progress_pi = Math.PI * (progress / 180 - 1 / 2);
context.beginPath();
context.moveTo(700, 400);
context.arc(700, 400, 80, 0, Math.PI * 2, false);
context.closePath();
context.fillStyle = '#4BF41B';
context.fill();
context.beginPath();
context.moveTo(700, 400);
context.arc(700, 400, 80, -Math.PI * 1 / 2, progress_pi, false);
context.closePath();
context.fillStyle = 'red'
context.lineCap = 'round';
context.fill();
context.beginPath();
context.arc(700, 400, 65, 0, Math.PI * 2, false);
context.closePath();
context.fillStyle = 'white';
context.fill();
context.font = "bold 40pt Arial";
context.fillStyle = "red";
context.textAlign = "center";
context.textBaseline = 'middle';
context.fillText(currentSeconds, 700, 400);
// 抗锯齿
context.globalCompositeOperation = 'source-atop';
currentSeconds--;
}
</script>
</body>
</html>
html5 canvas 倒计时
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1. 案例介绍 最近在慕课网上看了一门有关Canvas的课程案例,炫丽的倒计时效果Canvas绘图与动画基础,学习...
- github地址 https://github.com/bigrainbig/countdown一个简单的计时器