js时钟效果

拟墨画扇 提交于 2020-03-30 02:10:34

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title></title>
  <style type="text/css">
   *{
    margin: 0;
    padding: 0;
   }
   .box{
    width: 600px;
    height: 600px;
    margin: 0 auto;
    background: url(img/clock.jpg);
    position: relative;
   }
   #hour{
    width: 100%;
    height: 600px;  /*盒子大小必须的写*/
    background: url(img/hour.png) no-repeat center center;
    position: absolute;
   }
   #min{
    width: 100%;
    height: 100%;
    background: url(img/minute.png) no-repeat center center;
    position: absolute;
   }
   #second{
    width: 100%;
    height: 100%;
    background: url(img/second.png) no-repeat center center;
    position: absolute;
   }
  </style>
  <script type="text/javascript">
   window.onload = function(){
    var hour = document.getElementById('hour');
    var min = document.getElementById('min');
    var second = document.getElementById('second');
    setInterval(function(){
    var date = new Date();
    var s=0,m=0,h=0,ms=0;
    ms= date.getMilliseconds();
    s= date.getSeconds()+ms/1000;
    m = date.getMinutes()+s/60;
    h = date.getHours()%12+m/60;
    second.style.webkitTransform = 'rotate('+6*s+'deg)';
    min.style.webkitTransform = 'rotate('+6*m+'deg)';
    hour.style.webkitTransform = 'rotate('+30*h+'deg)';
    },1000);
    
    
   }
  </script>
 </head>
 <body>
  <div class="box">
   <div id="hour"></div>
   <div id="min"></div>
   <div id="second"></div>
  </div>
 </body>
</html>

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!