<!DOCTYPE html>
<html>
<head>
<title>Js版带表盘的时钟</title>
<meta charset="utf-8"/>
<link rel="Stylesheet" href="4_2.css"/>
<script src="4_2.js"></script>
</head>
<body>
<div id="clock">
<div id="h"></div>
<div id="m"></div>
<div id="s"></div>
<div id="a1">I</div>
<div id="a2">II</div>
<div id="a3">III</div>
<div id="a4">IIII</div>
<div id="a5">V</div>
<div id="a6">VI</div>
<div id="a7">VII</div>
<div id="a8">VIII</div>
<div id="a9">IX</div>
<div id="a10">X</div>
<div id="a11">XI</div>
<div id="a12">XII</div>
</div>
</body>
</html>
 #clock{width:100px; height:100px;
border-radius:50%;
border:2px solid black;
position:relative;
}
#s{width:2px; height:55px;
position:absolute; top:5px; left:49px;
background-color:red;
transform-origin:50% 45px;
}
#m{width:4px; height:50px;
position:absolute; top:10px; left:48px;
background-color:black;
transform-origin:50% 40px;
}
#h{width:6px; height:45px;
position:absolute; top:15px; left:47px;
background-color:black;
transform-origin:50% 35px;
}
div[id^="a"]{position:absolute;
font-size:.5em; text-align:center;
width:7px; height:5px;
top:; left: 46.5px;
transform-origin:50% 50px;
}
#a4,#a8{font-size:.4em; font-weight:bold}
#a1{transform:rotate(30deg)}
#a2{transform:rotate(60deg)}
#a3{transform:rotate(90deg)}
#a4{transform:rotate(120deg)}
#a5{transform:rotate(150deg)}
#a6{transform:rotate(180deg)}
#a7{transform:rotate(210deg)}
#a8{transform:rotate(240deg)}
#a9{transform:rotate(270deg)}
#a10{transform:rotate(300deg)}
#a11{transform:rotate(330deg)}

js代码:

 var clock={
divH:null,
divM:null,
divS:null,
start:function(){
var self=this;
self.divH=document.getElementById("h");
self.divM=document.getElementById("m");
self.divS=document.getElementById("s");
self.calc();
setInterval(function(){self.calc();},1000);//this.calc.bind(this);
},
calc:function(){
var now=new Date();
var h=now.getHours();
h>12&&(h-=12);
var m=now.getMinutes();
var s=now.getSeconds();
var sdeg=s*6;
var mdeg=m*((360-s/60)/60);
var hdeg=h*((360-mdeg/60)/12);
this.divH.style.transform="rotate("+hdeg+"deg)";
this.divM.style.transform="rotate("+mdeg+"deg)";
this.divS.style.transform="rotate("+sdeg+"deg)";
}
}
window.onload=function(){
clock.start();
}

效果展示!

最新文章

  1. Mysql 中文乱码(Navicat for MySQL)
  2. lightbox图片展示效果
  3. windows 安装oracle 后,所有服务都是什么意思,需要开户吗?
  4. C++学习笔记15:操作符重载的函数原型列表(推荐)
  5. BrnShop开源网上商城第三讲:插件的工作机制
  6. linux操作笔记
  7. spoj 375 QTREE - Query on a tree 树链剖分
  8. HDU 4284 Travel
  9. vpn探测
  10. xampp打开显示缺少运行库的解决方法
  11. (十一)QPainter绘图, QPixmap,QImage,QPicture,QBitmap
  12. .class文件查看
  13. centos6.8安装python3.7无法import _ssl
  14. wpf-x-指令元素
  15. Quartz.net创建windows服务
  16. JAVA面向对象编程之购物车界面的设计与功能的实现
  17. 怎么在eclipse中安装svn插件
  18. PHP代码审计笔记--XSS
  19. linux服务器---配置samba
  20. Python3.5 MySQL 数据库连接

热门文章

  1. Loadrunner中关联的作用:
  2. DSP using MATLAB示例Example3.16
  3. chrome插件
  4. css -- 高度相等的列 -- 3列高度相等
  5. java中 ==与equals 有什么区别?
  6. Linux下使用vsftp
  7. hiveserver2
  8. ACM: HDU 5285 wyh2000 and pupil-二分图判定
  9. 51Nod 1256 乘法逆元 Label:exgcd
  10. [知识点]A*搜索(启发式搜索)