1 <!DOCTYPE html>
  2 <html lang="en">
  3 <head>
  4     <meta charset="UTF-8">
  5     <title>clock</title>
  6 </head>
  7 <body>
  8     <canvas id="clock" width="500" height="500" style="display:block; margin:50px auto">
  9         您的浏览器不支持canvas标签!
 10     </canvas>
 11     <script>
 12         var clock = document.getElementById('clock');
 13         var ctx = clock.getContext('2d');
 14         function drawClock(){
 15             var today = new Date();
 16             var year = today.getFullYear();
 17             var month = today.getMonth() + 1;
 18             var date = today.getDate();
 19             var day = today.getDay();
 20             var hour = today.getHours();
 21             var minute = today.getMinutes();
 22             var second = today.getSeconds();
 23             hour = hour > 12 ? hour - 12 : hour;
 24 
 25             ctx.clearRect(0, 0, 500, 500);
 26 
 27             ctx.fillStyle = '#fff';
 28             ctx.beginPath();
 29             ctx.arc(250, 250, 205, 0, 2*Math.PI);
 30             ctx.closePath();
 31             ctx.fill();
 32 
 33             ctx.strokeStyle = '#ddd';
 34             ctx.lineWidth = 10;
 35             ctx.beginPath();
 36             ctx.arc(250, 250, 185, 0, 2*Math.PI);
 37             ctx.closePath();
 38             ctx.stroke();
 39 
 40             ctx.strokeStyle = '#96DFF7';
 41             ctx.lineWidth = 10;
 42             ctx.beginPath();
 43             ctx.arc(250, 250, 200, 0, 2*Math.PI);
 44             ctx.closePath();
 45             ctx.stroke();
 46 
 47             ctx.strokeStyle = '#96DFF7';
 48             ctx.lineWidth = 3;
 49             ctx.beginPath();
 50             ctx.arc(250, 250, 192, 0, 2*Math.PI);
 51             ctx.closePath();
 52             ctx.stroke();
 53 
 54             ctx.strokeStyle = '#09303C';
 55             ctx.lineWidth = 5;
 56             ctx.beginPath();
 57             ctx.arc(250, 250, 205, 0, 2*Math.PI);
 58             ctx.closePath();
 59             ctx.stroke();
 60 
 61             
 62             // 时刻度
 63             for(var i = 0; i < 12; i++) {
 64                 ctx.save();
 65                 ctx.lineWidth = 4;
 66                 ctx.strokeStyle = '#000';
 67                 ctx.translate(250, 250);
 68                 ctx.rotate(30 * i / 180 * Math.PI);
 69                 ctx.beginPath();
 70                 ctx.moveTo(0, 180);
 71                 ctx.lineTo(0, 160);
 72                 ctx.closePath();
 73                 ctx.stroke();
 74                 ctx.restore();
 75             }
 76             // 分刻度
 77             for(var i = 0; i < 60; i++) {
 78                 if(i % 5 != 0){
 79                     ctx.save();
 80                     ctx.lineWidth = 2;
 81                     ctx.strokeStyle = '#000';
 82                     ctx.translate(250, 250);
 83                     ctx.rotate(6 * i / 180 * Math.PI);
 84                     ctx.beginPath();
 85                     ctx.moveTo(0, 175);
 86                     ctx.lineTo(0, 170);
 87                     ctx.closePath();
 88                     ctx.stroke();
 89                     ctx.restore();
 90                 }
 91             }
 92 
 93             // 秒针
 94             ctx.save();
 95             ctx.lineWidth = 2;
 96             ctx.strokeStyle = "#f00";
 97             ctx.beginPath();
 98             ctx.translate(250, 250);
 99             ctx.rotate((second * 6 + 180) / 180 * Math.PI);
100             ctx.moveTo(0, 0);
101             ctx.lineTo(0, 150);
102             ctx.closePath();
103             ctx.stroke();
104             ctx.restore();
105 
106             // 分针
107             ctx.save();
108             ctx.lineWidth = 4;
109             ctx.strokeStyle = "#0ff";
110             ctx.beginPath();
111             ctx.translate(250, 250);
112             ctx.rotate((minute * 6 + second * 0.1 + 180) / 180 * Math.PI);
113             ctx.moveTo(0, 0);
114             ctx.lineTo(0, 130);
115             ctx.closePath();
116             ctx.stroke();
117             ctx.restore();
118 
119             // 时针 
120             ctx.save();
121             ctx.lineWidth = 6;
122             ctx.strokeStyle = "#000";
123             ctx.beginPath();
124             ctx.translate(250, 250);
125             ctx.rotate((hour * 30 + minute * 0.5 + 180) / 180 * Math.PI);
126             ctx.moveTo(0, 0);
127             ctx.lineTo(0, 90);
128             ctx.closePath();
129             ctx.stroke();
130             ctx.restore(); 
131 
132             ctx.fillStyle = "#f00";
133             ctx.beginPath();
134             ctx.arc(250, 250, 10, 0, 2 * Math.PI);
135             ctx.closePath();
136             ctx.fill();
137             ctx.fillStyle = "#000";
138             ctx.beginPath();
139             ctx.arc(250, 250, 8, 0, 2 * Math.PI);
140             ctx.closePath();
141             ctx.fill();
142             ctx.fillStyle = "#fff";
143             ctx.beginPath();
144             ctx.arc(250, 250, 6, 0, 2 * Math.PI);
145             ctx.closePath();
146             ctx.fill();
147 
148         }
149         drawClock();
150         setInterval(drawClock,10);
151     </script>
152 </body>
153 </html>

posted @ 2015-10-22 16:22 阁楼小洁 阅读(168) 评论(0) 推荐(0)
摘要: Iscroll.js使用之后页面上面A标签的onclick事件无效了解决办法实例化IScroll的时候把preventDefault设为false,默认为true 1 var myScroll; 2 function loaded () { 3 myScroll = new ... 阅读全文
posted @ 2015-09-25 10:03 阁楼小洁 阅读(2068) 评论(1) 推荐(0)
摘要: 1 /** 2 * Created by linjie on 2015/9/1. 3 */ 4 5 body,h1,h2,h3,h4,h5,h6,p,dl,dd,ul,ol,form,button,select,input,textarea,th,td{ margin: 0; padding... 阅读全文
posted @ 2015-09-01 13:19 阁楼小洁 阅读(216) 评论(0) 推荐(0)
摘要: 先来看下 ie、火狐、谷歌浏览器下各个字体显示情况ie下:火狐下:谷歌下:从上面的图可以很明显看出谷歌下 css设置字体大小为12px及以下时,显示都是一样大小,都是默认12px;那么网上一直有一个方法就是给当前样式添加谷歌私有属性:-webkit-text-size-adjust:none;可是我... 阅读全文
posted @ 2015-06-25 10:58 阁楼小洁 阅读(596) 评论(0) 推荐(0)
摘要: 因为有父, 子节点同在, 因为有监听事件和浏览器默认动作之分. 使用 JavaScript 时为了达到预期效果经常需要阻止事件和动作执行. 一般我们会用到三种方法, 分别是stopPropagation(),preventDefault()和return false. 它们之间有什么区别, 该何时使... 阅读全文
posted @ 2015-06-25 10:57 阁楼小洁 阅读(259) 评论(0) 推荐(0)
摘要: 解决IE6,IE7下子元素使用position:relative、父元素使用overflow:auto后,子元素不随着滚动条滚动的问题在IE6,IE7下,子元素使用position:relative、父元素使用overflow:auto后,我们预期的是滚动条滚动时,子元素也随着滚动,实际情况是内容不... 阅读全文
posted @ 2015-06-25 10:56 阁楼小洁 阅读(463) 评论(0) 推荐(0)
摘要: SublimeText是一款非常精巧的文本编辑器,适合编写代码、做笔记、写文章。它用户界面十分整洁,功能非同凡响,性能快得出奇。这些非常棒的特性 包括任意跳转(Goto Anything)、多重选择(multiple selections)、指令面板(command palette)、免打扰模式(d... 阅读全文
posted @ 2015-06-25 10:45 阁楼小洁 阅读(262) 评论(0) 推荐(0)
摘要: 自动安装:1、通过快捷键 ctrl+` 或者 View > Show Console 菜单打开控制台2、粘贴对应版本的代码后回车安装适用于 Sublime Text 3:import urllib.request,os;pf='Package Control.sublime-package';ipp... 阅读全文
posted @ 2015-06-25 10:42 阁楼小洁 阅读(135) 评论(0) 推荐(0)
摘要: 选择类Ctrl+D 选中光标所占的文本,继续操作则会选中下一个相同的文本。Alt+F3选中文本按下快捷键,即可一次性选择全部的相同文本进行同时编辑。举个栗子:快速选中并更改所有相同的变量名、函数名等。Ctrl+L选中整行,继续操作则继续选择下一行,效果和 Shift+↓ 效果一样。Ctrl+Shif... 阅读全文
posted @ 2015-06-25 10:34 阁楼小洁 阅读(135) 评论(0) 推荐(0)
摘要: 1.块元素和内嵌元素(block\inline) 块的特征: 独占一行 不设定宽度,宽度将撑满整行 能设置所有样式 内嵌的特征: 默认同行可以继续跟同类型标签 内容撑开宽度 不支持宽高 不支持上下的margin和padding 空格或换行时,会出现空格,并且间隙不兼容(解决方案:给全局设置:font-size、font-family) 块标签:div,h1-h6,p,ul,ol,li,dl,dd,dt 内嵌标签:span,a,strong,em2.特殊的inline-block标签 img inline... 阅读全文
posted @ 2013-12-06 15:58 阁楼小洁 阅读(136) 评论(0) 推荐(0)
点击右上角即可分享
微信分享提示