爱易网
IT新闻
IT新闻
爱易资讯
网站搭建
云虚拟主机教程
云服务器教程
Apache教程
IIS教程
Nginx教程
网站策划
站长文章
推广教程
淘宝客教程
网页设计
HTML教程
XHTML教程
CSS教程
HTML5教程
CSS3教程
JavaSript基础
JQuery教程
Node.js教程
前端技术
Ajax教程
Js特效
Xml教程
平面设计
页面UI设计
photoshop教程
程序开发
AI人工智能
Asp教程
Php教程
Asp.Net教程
Net Core教程
C#教程
Java教程
Jsp教程
开发技术
微信小程序教程
Uniapp开发教程
微信公众号开发
Andriod教程
IOS教程
DOS教程
Python教程
Docker教程
Windows Container教程
数据库
MSSQL教程
MySQL教程
Redis教程
Access教程
Oracle教程
数据库教程
操作系统
Linux教程
Windows教程
MAC教程
Cisco教程
交换机教程
防火墙教程
搜索
爱易网页
JS特效
HTML5标准,一个Canvas时钟特效演示
HTML5标准,一个Canvas时钟特效演示
日期:2014-05-18 浏览次数:20266 次
以下是程序代码
<!DOCTYPE html> <html> <head> <title>canvas时钟</title> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> </head> <body> <canvas id="canvas" width="200" height="200" style="border:1px solid #000;">您的浏览器不支持Canvas。</canvas> <script type="text/javascript" language="javascript" charset="utf-8"> var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); if(ctx){ var timerId; var frameRate = 60; function canvObject(){ this.x = 0; this.y = 0; this.rotation = 0; this.borderWidth = 2; this.borderColor = '#000000'; this.fill = false; this.fillColor = '#ff0000'; this.update = function(){ if(!this.ctx)throw new Error('你没有指定ctx对象。'); var ctx = this.ctx ctx.save(); ctx.lineWidth = this.borderWidth; ctx.strokeStyle = this.borderColor; ctx.fillStyle = this.fillColor; ctx.translate(this.x, this.y); if(this.rotation)ctx.rotate(this.rotation * Math.PI/180); if(this.draw)this.draw(ctx); if(this.fill)ctx.fill(); ctx.stroke(); ctx.restore(); } }; function Line(){}; Line.prototype = new canvObject(); Line.prototype.fill = false; Line.prototype.start = [0,0]; Line.prototype.end = [5,5]; Line.prototype.draw = function(ctx){ ctx.beginPath(); ctx.moveTo.apply(ctx,this.start); ctx.lineTo.apply(ctx,this.end); ctx.closePath(); }; function Circle(){}; Circle.prototype = new canvObject(); Circle.prototype.draw = function(ctx){ ctx.beginPath(); ctx.arc(0, 0, this.radius, 0, 2 * Math.PI, true); ctx.closePath(); }; var circle = new Circle(); circle.ctx = ctx; circle.x = 100; circle.y = 100; circle.radius = 90; circle.fill = true; circle.borderWidth = 6; circle.fillColor = '#ffffff'; var hour = new Line(); hour.ctx = ctx; hour.x = 100; hour.y = 100; hour.borderColor = "#000000"; hour.borderWidth = 10; hour.rotation = 0; hour.start = [0,20]; hour.end = [0,-50]; var minute = new Line(); minute.ctx = ctx; minute.x = 100; minute.y = 100; minute.borderColor = "#333333"; minute.borderWidth = 7; minute.rotation = 0; minute.start = [0,20]; minute.end = [0,-70]; var seconds = new Line(); seconds.ctx = ctx; seconds.x = 100; seconds.y = 100; seconds.borderColor = "#ff0000"; seconds.borderWidth = 4; seconds.rotation = 0; seconds.start = [0,20]; seconds.end = [0,-80]; var center = new Circle(); center.ctx = ctx; center.x = 100; center.y = 100; center.radius = 5; center.fill = true; center.borderColor = 'orange'; for(var i=0,ls=[],cache;i<12;i++){ cache = ls[i] = new Line(); cache.ctx = ctx; cache.x = 100; cache.y = 100; cache.borderColor = "orange"; cache.borderWidth = 2; cache.rotation = i * 30; cache.start = [0,-70]; cache.end = [0,-80]; } timerId = setInterval(function(){ // 清除画布 ctx.clearRect(0,0,200,200); // 填充背景色 ctx.fillStyle = 'orange'; ctx.fillRect(0,0,200,200); // 表盘 circle.update(); // 刻度 for(var i=0;cache=ls[i++];)cache.update(); // 时针 hour.rotation = (new Date()).getHours() * 30; hour.update(); // 分针 minute.rotation = (new Date()).getMinutes() * 6; minute.update(); // 秒针 seconds.rotation = (new Date()).getSeconds() * 6; seconds.update(); // 中心圆 center.update(); },(1000/frameRate)|0); }else{ alert('您的浏览器不支持Canvas无法预览.\n跟我一起说:"Fuck Internet Exploer!"'); } </script> </body> <
上一篇:狡猾的按钮特效
下一篇:js按指定格式显示日期时间样式特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
支付宝曝平安破绽:转账信息被谷歌抓取
易迅大众点评缩水执行“七天后悔权”被约谈
全球五大电信设备商业绩:华为净利居首
iOS7拖累iPad 5、iPad mini2发布 传十月份推出
2019双12阿里云老用户怎么参加拼团活动 老用户拼团方法
京东确定IPO定价区间 最高募资16.9亿美元
靠价格战赚取资费套餐利润差,虚拟运营商必死无疑
墨迹也要做硬件,工具类应用如何“变异”的
亚马逊Fire Phone:请别拿我跟苹果三星比
推荐阅读
更多>
HTC的三大迷惘:高管釜底抽薪 产品营销战略混乱
阿朗力避步北电后尘 急切停止自我革新
全球最具“颠覆性”特质的公司排行榜TOP25
杨元庆去年总薪酬1.33亿元
苏宁双线同价遇难题:第一个吃螃蟹不轻松
总部大楼已换微软Logo:回忆诺基亚的兴衰史
可靠消息称微型针孔偷拍设备拟全面禁止
百度“全网寻人”面前的互联网信息枢纽价值
蓝宝石PK大猩猩玻璃:作为屏幕谁更有优势?
火狐手机发展前路:或被运营商绑架
国网公司将加快组建 业界人士称困难重重
中国雅虎邮箱今日关停 由盛及衰的背后
盘点改变社会的15种科技:谷歌眼镜将使我们成为半机械人
马斯克的特斯拉能否保持好势头
摩托罗拉中国区将再裁员 助力公司变身
传4G牌照国庆节前后发放 TD-LTE制式优先
中方抗议美方限购IT设备 紧张关系加剧
微软最后的救命稻草Win 8份额继续上升
京东进驻微信一级入口或影响自身战略布局
埃里克杰克森:阿里IPO估值至少1500亿美元