爱易网
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 浏览次数:20261 次
以下是程序代码
<!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按指定格式显示日期时间样式特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
网曝富士康500万iphone遭退货是确证的事
百度透露无人驾驶战略 研发三维交通地图
iPhone 6 Plus要召回是谣言
HDS发布《2013中国CIO洞察白皮书》
苹果20年以来首次发债 融资170亿美元
巧用百度推行系统 突显竞价效果
国美苏宁线上首度正面PK 京东列席4月电商战
百视通:Xbox One汉化获批 游戏迷欢呼吧
打车软件“明补变暗补”背后的小算盘
推荐阅读
更多>
PC迎9年来出货量新低 平板电脑渐成主流
微软小冰复活再战移动端:改与米聊、易信和触宝合作
为啥苹果定要出廉价iPhone?都是安卓逼的
苹果售后生态链乱象:供需失衡价钱不一
支付宝曝平安破绽:转账信息被谷歌抓取
电信设备商淘金中国4G:华为中兴领衔
Facebook思科联手推免费WiFi 欲覆盖全美
全球五大电信设备商业绩:华为净利居首
联想架构调整后:Think品牌或推智能手机
诺基亚再缩阵线 封锁上海旗舰店全力蜕变
“扫黄打非”下9158否认遭整顿
国美痛批网购七宗罪 用短暂盈利输了未来
支付宝被曝严重破绽 隐私平安再受质疑
逆转猜想:如果阿里成为雅虎大股东会怎样?
苹果6月20日发布iPhone5S 触摸屏概念股生动
电信业营改增今起实施 运营商短期利润骤降
盛大游戏走向衰落的根源:免费游戏模式惹的祸
O2O成"唐僧肉":百度糯米抢食第一口令阿里腾讯颤抖
网络文学竞争白热化 百度多酷文学网上线
说说这一个月的赌球输了多少