js时钟效果

<!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>

 

posted @ 2018-03-12 13:34  丢嫂  阅读(105)  评论(0编辑  收藏  举报