DDR爱好者之家 Design By 杰米

本文实例为大家分享了js流动式时间的实现代码,供大家参考,具体内容如下

效果图:

js流动式效果显示当前系统时间

实现代码:

<!DOCTYPE html>
<html>

 <head>
  <title>js流动时间</title>
  <style type="text/css">
   #divH,
   #divM,
   #divS {
    font-family: consal;
    line-height: 30px;
    position: absolute;
    left: 0px;
    width: 5760px;
    color: white;
   }

   #divH {
    background-color: #606;
   }

   #divM {
    background-color: #060;
   }

   #divS {
    background-color: #006;
   }

   #divH div,
   #divM div,
   #divS div {
    float: left;
    border-right: solid 1px gray;
    text-align: center;
   }
  </style>
 </head>

 <body>
  <div style="font-family:Arial; width:400px; font-size:24px;">
   <div id="divTime" style="text-align:center; line-height:1.5;">Time</div>
   <div style="outline:solid 5px gray; position:relative; overflow:hidden; height:90px;">
    <div id="divH" style="top:0px;"></div>
    <div id="divM" style="top:30px;"></div>
    <div id="divS" style="top:60px;"></div>
    <div id="divLine" style="position:absolute; top:0px; left:50%; border-left:solid 1px red; height:90px;"></div>
   </div>
  </div>
  <script type="text/javascript">
   var divH = document.getElementById('divH');
   var divM = document.getElementById('divM');
   var divS = document.getElementById('divS');
   var divTime = document.getElementById('divTime');
   var aw = 2880;
   var ww = 400;
   var w = aw / 24;
   for (var i = 0; i < 48; i++) {
    var div = document.createElement('div');
    div.style.width = (w - 1) + 'px';
    div.innerHTML = i % 24;
    divH.appendChild(div);
   }
   w = aw / 60;
   for (var i = 0; i < 120; i++) {
    var div = document.createElement('div');
    div.style.width = (w - 1) + 'px';
    div.innerHTML = i % 60;
    divM.appendChild(div);
   }
   w = aw / 60;
   for (var i = 0; i < 120; i++) {
    var div = document.createElement('div');
    div.style.width = (w - 1) + 'px';
    div.innerHTML = i % 60;
    divS.appendChild(div);
   }
   window.setInterval(run, 20);

   function run() {
    var dt = new Date();
    var h = dt.getHours();
    var m = dt.getMinutes();
    var s = dt.getSeconds();
    var f = dt.getMilliseconds();
    divH.style.left = ((h > 12) ":" + s;
   }
  </script>
 </body>

</html>

以上就是本文的全部内容,希望对大家学习javascript程序设计有所帮助。

DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米