" />
废话不多说了,直接给大家贴代码了,具体代码如下所示:
<!doctype html><html lang="en"><head> <meta c双鱼座女孩性格hart="utf-8"> <title>canvas_time</title> <style type="text/css"> div { text-align: center; margin-top: 250px; } #clock { border: 1px solid #cccccc; } </style></head><body> <div> <canvas id="clock" height="600px" width="600px"></canvas> </div> <script type="text/javascript" >var dom = document.getelementbyid('clock');var ctx = dom.getcontext('2d');var width = ctx.canvas.width;var height = ctx.canvas.height;var r = width / 2;var rem = width/200;function drawbackground() { ctx.save(); //存储当前环境变量; ctx.translate(r, r); //重置坐标到r,r ctx.beginpath(); // 起始一条路径 ctx.linewidth = 10*rem; //设置线宽10; ctx.arc(0, 0, r - ctx.linewidth /2, 0, 2 * math.pi, fal); ctx.stroke(); var hournumbers = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2]; //定义数组 ctx.font = 18*rem+"px arial"; ctx.textalign = "center"; ctx.textbaline = "middle"; hournumbers.foreach(function(number, i) { var rad = 2 * math.pi / 12 * i; var x = math.cos(rad) * (r - 30*rem); var y = math.sin(rad) * (r - 30*rem); ctx.filltext(number, x, y); }); for (var i = 0; i < 60; i++) { var rad = 2 * math.pi / 60高三物理 * i; var x = math.cos(rad) * (r - 18*rem); var y = math.sin(rad) * (r - 18*rem); ctx.beginpath(); if (i % 5 === 0) { ctx.arc(x, y, 2*rem, 0, 2 * math.pi, fal); ctx.fillstyle = "#000"; } el { ctx.arc(x, y, 2*rem, 0, 2 * math.pi, fal); ctx.fillstyle = "#ccc"; } ctx.fill(); }} function drawhour(hour, minute) { ctx.save(); ctx.beginpath(); var rad = 2 * math.pi / 12 * hour; var mrad = 2 * math.pi / 12 / 60 * minute; ctx.rotate(rad + mrad); ctx.linewidth = 6*rem; ctx.linecap = "round"; ctx.moveto(0, 10*rem); ctx.lineto(0, -r / 2); ctx.stroke(); ctx.restore(); } function drawminute(minute) { ctx.save(); ctx.beginpath(); var rad = 2 * math.pi / 60 * minute; ctx.rotate(rad); ctx.linewidth = 3*rem; ctx.linecap = "round"; ctx.moveto(0, 10*rem); ctx.lineto(0, -r + 30*rem); ctx.stroke(); ctx.restore(); 高一物理必修1公式 } function drawcond(cond) { ctx.save(); ctx.beginpath(); ctx.fillstyle = 'red'; var rad = 2 * math.pi / 60 * cond; ctx.rotate(rad); ctx.moveto(-2*rem, 20*rem); ctx.lineto(2*rem, 20*rem); 相约中国 ctx.lineto(1, -r + 16*rem); ctx.lineto(-1, -r + 16*rem); ctx.fill(); ctx.restore(); } function drawdot() { ctx.beginpath(); ctx.fillstyle = '#fff'; ctx.arc(0, 0, 3*rem, 0, 2 * math.pi, fal); ctx.fill(); } function draw01() { ctx.clearrect(0, 0, width, height); var now = new date(); var hour = now.gethours(); var minute学前专业 = now.getminutes(); var cond = now.getconds(); drawbackground(); drawhour(hour, minute); drawminute(minute); drawcond(cond); drawdot(); ctx.restore(); } draw01(); tinterval(draw01, 1000);</script></body></html>
总结
以上所述是www.887551.com给大家介绍的html5实现可缩放时钟代码,希望对大家有所帮助
本文发布于:2023-04-06 11:40:34,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/96809de52a929b10c9099d9097a82186.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:HTML5实现可缩放时钟代码.doc
本文 PDF 下载地址:HTML5实现可缩放时钟代码.pdf
留言与评论(共有 0 条评论) |