body{
background:#202020;
font:bold 12px Arial, Helvetica, sans-serif;
margin:0;
padding:0;
min-width:960px;
color:#bbbbbb;
}
a {
text-decoration:none;
color:#00c6ff;
}
h1 {
font: 4em normal Arial, Helvetica, sans-serif;
padding: 20px; margin: 0;
text-align:center;
}
h1 small{
font: 0.2em normal Arial, Helvetica, sans-serif;
text-transform:uppercase; letter-spacing: 0.2em; line-height: 5em;
display: block;
}
h2 {
font-weight:700;
color:#bbb;
font-size:20px;
}
h2, p {
margin-bottom:10px;
}
@font-face {
font-family: 'BebasNeueRegular';
src: url('BebasNeue-webfont.eot');
src: url('BebasNeue-webfont.eot?#iefix') format('embedded-opentype'),
url('BebasNeue-webfont.woff') format('woff'),
url('BebasNeue-webfont.ttf') format('truetype'),
url('BebasNeue-webfont.svg#BebasNeueRegular') format('svg');
font-weight: normal;
font-style: normal;
}
.container {width: 960px; margin: 0 auto; overflow: hidden;}
.clock {width:800px; margin:0 auto; padding:30px; border:1px solid #333; color:#fff; }
#Date { font-family:'BebasNeueRegular', Arial, Helvetica, sans-serif; font-size:36px; text-align:center; text-shadow:0 0 5px #00c6ff; }
ul { width:800px; margin:0 auto; padding:0px; list-style:none; text-align:center; }
ul li { display:inline; font-size:10em; text-align:center; font-family:'BebasNeueRegular', Arial, Helvetica, sans-serif; text-shadow:0 0 5px #00c6ff; }
#point { position:relative; -moz-animation:mymove 1s ease infinite; -webkit-animation:mymove 1s ease infinite; padding-left:10px; padding-right:10px; }
@-webkit-keyframes mymove
{
0% {opacity:1.0; text-shadow:0 0 20px #00c6ff;}
50% {opacity:0; text-shadow:none; }
100% {opacity:1.0; text-shadow:0 0 20px #00c6ff; }
}
@-moz-keyframes mymove
{
0% {opacity:1.0; text-shadow:0 0 20px #00c6ff;}
50% {opacity:0; text-shadow:none; }
100% {opacity:1.0; text-shadow:0 0 20px #00c6ff; }
}
#hours{color:red}
#min{color:green}
#hours{color:blue}
#c1,#myCanvas{background:white;}
.c2,.c3{margin:10px auto;width:400px; height:400px;}
.c2{float:left}
.c3{float:right}
.clocks {
height: 500px;
margin: 25px auto;
position: relative;
width: 500px;
}
$(document).ready(function() {
// Create two variable with the names of the months and days in an array
var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
var dayNames= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
// Create a newDate() object
var newDate = new Date();
// Extract the current date from Date object
newDate.setDate(newDate.getDate());
// Output the day, date, month and year
$('#Date').html(dayNames[newDate.getDay()] + " " + newDate.getDate() + ' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getFullYear());
setInterval( function() {
// Create a newDate() object and extract the seconds of the current time on the visitor's
var seconds = new Date().getSeconds();
// Add a leading zero to seconds value
$("#sec").html(( seconds < 10 ? "0" : "" ) + seconds);
},1000);
setInterval( function() {
// Create a newDate() object and extract the minutes of the current time on the visitor's
var minutes = new Date().getMinutes();
// Add a leading zero to the minutes value
$("#min").html(( minutes < 10 ? "0" : "" ) + minutes);
},1000);
setInterval( function() {
// Create a newDate() object and extract the hours of the current time on the visitor's
var hours = new Date().getHours();
// Add a leading zero to the hours value
$("#hours").html(( hours < 10 ? "0" : "" ) + hours);
}, 1000);
});
window.onload = function(){
var oc = document.getElementById('c1');//获取元素
var ogc=oc.getContext('2d');//获取绘图环境
function toDraw(){
var x = 200;
var y = 200;
var r = 150;
ogc.clearRect(0,0,oc.width,oc.height);//清除画布以避免叠加显示
var odate=new Date();
var ohours=odate.getHours();//获取本地时间时值
var omin=odate.getMinutes();//获取本地时间分值
var osec=odate.getSeconds();//获取本地时间秒值
var ohoursvalue=(-90+ohours*30+omin/2)*Math.PI/180;//根据获得的时间值计算出时针的弧度
var ominvalue=(-90+omin*6)*Math.PI/180;//根据获得的时间值计算出分针的弧度
var osecvalue=(-90+osec*6)*Math.PI/180;//根据获得的时间值计算出秒针的弧度
/*ogc.moveTo(x,y);
ogc.arc(x,y,r,0,6*Math.PI/180,12*Math.PI/180,false);*/
ogc.beginPath();//开始绘制一个大圆 大圆有for循环实现60次的6弧度圆弧
for(var i=0;i<60;i++){
ogc.moveTo(x,y);//每次移动到大圆中心点
ogc.arc(x,y,r,6*i*Math.PI/180,6*(i+1)*Math.PI/180,false);
}
ogc.closePath();//60次绘制后结束绘制如图1
ogc.stroke();//结束绘制
ogc.fillStyle="white";//填充为白色的半径为原来19/20的圆 如图2
ogc.beginPath();
ogc.moveTo(x,y);
ogc.arc(x,y,r*19/20,0,360*(i+1)*Math.PI/180,false);
ogc.closePath();
ogc.fill();
ogc.lineWidth="4";
ogc.beginPath();//开始绘制一个大圆 大圆有for循环实现12次的30弧度圆弧
for(var i=0;i<12;i++){
ogc.moveTo(x,y);//每次移动到大圆中心点
ogc.arc(x,y,r,30*i*Math.PI/180,30*(i+1)*Math.PI/180,false);
}
ogc.closePath();//12次绘制后结束绘制如图3
ogc.stroke();
ogc.fillStyle="white";//填充为白色的半径为原来19/20的圆 如图4
ogc.beginPath();
ogc.moveTo(x,y);
ogc.arc(x,y,r*18/20,0,360*(i+1)*Math.PI/180,false);
ogc.closePath();
ogc.fill();
ogc.lineWidth="5";//时针的线性显示的粗细值
ogc.beginPath();
ogc.moveTo(x,y);
ogc.arc(x,y,r*10/20,ohoursvalue,ohoursvalue,false);//绘制时针 由变量oohoursvalue动态的绘制出时针的位置不断的变动
ogc.closePath();//
ogc.stroke();
ogc.lineWidth="3";
ogc.beginPath();
ogc.moveTo(x,y);
ogc.arc(x,y,r*14/20,ominvalue,ominvalue,false);//绘制分针 由变量ominvalue动态的绘制出分针的位置不断的变动
ogc.closePath();//
ogc.stroke();
ogc.lineWidth="1";
ogc.beginPath();
ogc.moveTo(x,y);
ogc.arc(x,y,r*19/20,osecvalue,osecvalue,false);//绘制秒针 由变量osecvalue动态的绘制出秒针的位置不断的变动
ogc.closePath();//
ogc.stroke();
}
setInterval(toDraw,1000);//定时器 每隔一秒执行toDraw一次 对应上面的清除画布一次
toDraw();//调用自定义函数
};
- :
- :
var c = document.getElementById("myCanvas");
var cxt = c.getContext("2d");
var slen = 60;
var mlen = 48;
var hlen = 35;
cxt.strokeRect(0, 0, c.width, c.height);
cxt.beginPath();
cxt.arc(200, 150, 100, 0, 2 * Math.PI, true);
cxt.stroke();
cxt.closePath();
cxt.beginPath();
cxt.translate(200, 150);
cxt.rotate(-Math.PI / 2);
cxt.save();
for (var i = 0; i < 60; i++) {
if (i % 5 == 0) {
cxt.fillRect(84, -3, 16, 6);
cxt.fillText("" + (i / 5 == 0 ? 12 : (i / 5>9?i/5:"0"+i/5)), 70, 3);
} else {
cxt.fillRect(90, -1, 10, 2);
}
cxt.rotate(Math.PI / 30);
}
cxt.closePath();
var s = 0, m = 0, h = 0;
function Refresh() {
cxt.restore();
cxt.save();
cxt.rotate(s * Math.PI / 30);
cxt.clearRect(-13, -2, slen+2, 4);
cxt.restore();
cxt.save();
cxt.rotate((m+s/60) * Math.PI / 30);
cxt.clearRect(-11, -2, slen+2, 4);
cxt.restore();
cxt.save();
cxt.rotate((h+m/60) * Math.PI / 6);
cxt.clearRect(-9, -3, slen+2, 5);
cxt.restore();
cxt.save();
var time = new Date();
s =time.getSeconds();
m =time.getMinutes();
h =time.getHours();
cxt.rotate((h+m/60) * Math.PI / 6);
cxt.fillRect(-8, -2, hlen, 4);
cxt.restore();
cxt.save();
cxt.rotate((m+s/60) * Math.PI / 30);
cxt.fillRect(-10, -1.5, mlen, 3);
cxt.restore();
cxt.save();
cxt.rotate(s * Math.PI / 30);
cxt.fillStyle='#2e2';
cxt.fillRect(-12, -1, slen, 2);
}
var MyInterval = setInterval("Refresh();", 1000);