爱易网
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 浏览次数:20250 次
以下是程序代码
<!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按指定格式显示日期时间样式特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
挂号网高管团体离任 或因投资人失掉决计
中移动将推出多项4G资费新政
薛蛮子取保后首次发微博表示:辜负你们了
余额宝收益率跌破5% 银行系宝宝收益率赶超
聚美优品获基石投资1.5亿美金,IPO吃下定心丸
618首日看京东阿里不同策略,鹿死谁手?
网络视频的几大趋势将成视频玩家躲不开的发力点
打车软件“明补变暗补”背后的小算盘
支付宝曝平安破绽:转账信息被谷歌抓取
推荐阅读
更多>
巧用百度推行系统 突显竞价效果
雅安地震 绝不宽恕应用人们爱心的骗子!
阿里国际化再落子:2.49亿美元投资新加坡邮政
蜗牛移动董事长石海:号卡被叫停属乌龙事件
苹果联合创始人炮轰鲍尔默“一直都在吃老本”
支付宝曝平安破绽:转账信息被谷歌抓取
京东物流"最后一公里":颠覆阿里或者被阿里干掉
微信今天大面积崩溃 腾讯:因光缆施工被挖断
中电信国际漫游费下调85% 世界杯上网28元/天
二维码支付大战的号角注定已经吹响,尚需标准发放
FDD牌照短期不会发放 联通电信暗自提速建网
2018年阿里云双11活动如何参加?1折优惠大攻略
9月1日起免征新能源汽车购置税
眼球识别技术EyeVerify融资600万美元 360参投
用友软件股价逆势下跌 再融资方案现曙光
靠谱分析:6月发生的WWDC和谷歌I/O大会,将会出现哪些新产品?
北京今日实现用支付宝钱包为公交卡充值
“合聚变”来了 UC优视确认并入阿里巴巴
智能手机:中国手机市场最受关注十五款产品清点
传陌陌或12月赴美IPO 估值约30亿美元