爱易网
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 浏览次数:20296 次
以下是程序代码
<!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按指定格式显示日期时间样式特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
苹果优势逐渐丧失 传即将推出廉价iPhone
亚马逊推特价闪购纪念入华十周年 总裁一职仍空缺
微软不会被颠覆
罗永浩工匠形象坍塌,锤子产能再跳水逃离用户超两成
携程收买酷讯成定局:转型互联网+投资
马云自称在美国曾被绑票
郭美美事件推手被抓 “秦火火”拷问网络底线
历史惊人相似:如今的库克 曾经的鲍尔默
云储存有多远:跨过数据安全问题即可到达
推荐阅读
更多>
唯品会股价飙升 引天猫当当京东进军闪购
频繁自杀 折射媒体变革中的媒体人迷茫与压力并存
支付宝钱包支持医保移动缴费 广州成首个试点
腾讯微信昨晚再现大规模故障 多地受到影响
戴尔正告继续上市存风险 称黑石伊坎方案有缺乏
可靠消息称微型针孔偷拍设备拟全面禁止
全球网络遭史上最大规模攻击:攻击数据每秒300G
《中国三网融合业务运营管理》研讨报告征订函
易信工具性优势突出 丁磊三板斧或先砍在飞信上
虚拟运营商前路迷茫 业界建议发力车联网
诺基亚称不会更名“微软移动” 5月还将发布新品
特斯拉将获上海免费牌照 充电桩面临双重标准
纸媒深探版权蓝海抗衡互联网的时机到来了
二代 iPad Air将配备2GB内存?为同屏多任务做准备
国美痛批网购七宗罪 用短暂盈利输了未来
百度吴恩达:图像和音视频搜索是人工智能新方向
京东终于想明白,这些年错过的财运,都藏在女人的时装下
凑足了升级ios8所需要的5.7G空间,没料到“苹果”却变成“板砖”,iOS8还能一起愉快玩耍吗?
虚拟运营商流量不清零吸引用户 盈利待明
在线音乐出现“小米公司”不是没有可能