欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

HTML 罗盘式时钟的实现

程序员文章站 2022-06-18 18:50:47
HTML 罗盘式时钟的实现 看着有点黑科技的感觉就跟前段时间比较火的抖音动态时间那个一个效果,本文主要介绍了HTML 罗盘式时钟的实现,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小... 21-05-20...

代码块:

<!doctype html>
   <html lang="zh-hans">
       <head>
           <meta charset="utf-8">
           <meta name="viewport" content="width=device-width, initial-scale=1.0">
           <meta http-equiv="x-ua-compatible" content="ie=edge">
           <title>js仿抖罗盘时钟</title>
           <style>
               *{
                   margin:0;
                   padding:0
              }
              html,body{
                   width:100%;
                   height:100%;
                   background-color:#000;
                   overflow:hidden
              }
              #clock{
                   position:relative;
                  width:100%;
                  height:100%;
                  background:#000
              }
              .label{
                   display:inline-block;
                   color:#4d4d4d;
                  text-align:center;
                  padding:0 5px;
                  font-size:19px;
                  transition:left 1s,top 1s;
                  transform-origin:0% 0%
             }
          </style>     
      </head>
      <body>
          <div id="clock"></div>
          <script>
              var monthtext=["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"];
              var daytext=["零一号","零二号","零三号","零四号","零五号","零六号","零七号","零八号","零九号","十号","十一号","十二号","十三号","十四号","十五号","十六号","十七号","十八号","十九号","二十号","二十一号","二十二号","二十三号","二十四号","二十五号","二十六号","二十七号","二十八号","二十九号","三十号","三十一号"];
              var weektext=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
              var hourtext=["零点","零一点","零两点","零三点","零四点","零五点","零六点","零七点","零八点","零九点","零十点","十一点","十二点","十三点","十四点","十五点","十六点","十七点","十八点","十九点","二十点","二十一点","二十二点","二十三点"];
              var minutetext=["零一分","零二分","零三分","零四分","零五分","零六分","零七分","零八分","零九分","零十分","十一分","十二分","十三分","十四分","十五分","十六分","十七分","十八分","十九分","二十分","二十一分","二十二分","二十三分","二十四分","二十五分","二十六分","二十七分","二十八分","二十九分","三十分","三十一分","三十二分","三十三分","三十四分","三十五分","三十六分","三十七分","三十八分","三十九分","四十分","四十一分","四十二分","四十三分","四十四分","四十五分","四十六分","四十七分","四十八分","四十九分","五十分","五十一分","五十二分","五十三分","五十四分","五十五分","五十六分","五十七分","五十八分","五十九分","六十分"];
              var secondstext=["零一秒","零二秒","零三秒","零四秒","零五秒","零六秒","零七秒","零八秒","零九秒","零十秒","十一秒","十二秒","十三秒","十四秒","十五秒","十六秒","十七秒","十八秒","十九秒","二十秒","二十一秒","二十二秒","二十三秒","二十四秒","二十五秒","二十六秒","二十七秒","二十八秒","二十九秒","三十秒","三十一秒","三十二秒","三十三秒","三十四秒","三十五秒","三十六秒","三十七秒","三十八秒","三十九秒","四十秒","四十一秒","四十二秒","四十三秒","四十四秒","四十五秒","四十六秒","四十七秒","四十八秒","四十九秒","五十秒","五十一秒","五十二秒","五十三秒","五十四秒","五十五秒","五十六秒","五十七秒","五十八秒","五十九秒","六十秒"];
              var clock;var monthlist=[];
              var daylist=[];
              var weeklist=[];
              var hourlist=[];
              var minutelist=[];
              var secondslist=[];
              var iscircle=false;
              var textset=[[monthtext,monthlist],[daytext,daylist],[weektext,weeklist],[hourtext,hourlist],[minutetext,minutelist],[secondstext,secondslist]];
              window.onload=function(){
                  init();
                  setinterval(function(){
                       runtime();
                       },100);
                      changeposition();
                      settimeout(function(){
                      changecircle();
                      },2000);
                  }
              function init(){
                  clock=document.getelementbyid('clock');
                  for(var i=0;i<textset.length;i++){
                     for(var j=0;j<textset[i][0].length;j++){
                          var temp=createlabel(textset[i][0][j]);
                         clock.appendchild(temp);textset[i][1].push(temp);
                      }
                  }
              }
              function createlabel(text)
              {
               var div=document.createelement('div');
              div.classlist.add('label');
              div.innertext=text;return div;
              }
              function runtime(){
                  var now=new date();
                  var month=now.getmonth();
                  var day=now.getdate();
                  var week=now.getday();
                  var hour=now.gethours();
                  var minute=now.getminutes();
                  var seconds=now.getseconds();
                  initstyle();
                  var nowvalue=[month,day-1,week,hour,minute,seconds];
                 for(var i=0;i<nowvalue.length;i++){
                     var num=nowvalue[i];
                     textset[i][1][num].style.color='#fff';
                  }
                  if(iscircle){
                     var widthmid=document.body.clientwidth/2;
                     var heightmid=document.body.clientheight/2;
                     for(var i=0;i<textset.length;i++){
                         for(var j=0;j<textset[i][0].length;j++){
                             var r=(i+1)*35+50*i;
                             var deg=360/textset[i][1].length*(j-nowvalue[i]);
                             var x=r*math.sin(deg*math.pi/180)+widthmid;
                             var y=heightmid-r*math.cos(deg*math.pi/180);
                             var temp=textset[i][1][j];
                             temp.style.transform='rotate('+(-90+deg)+'deg)';
                             temp.style.left=x+'px';
                             temp.style.top=y+'px';
                         }
                     }
                 }
             }
             function initstyle(){
                 var label=document.getelementsbyclassname('label');
                 for(var i=0;i<label.length;i++){
                     label[i].style.color='#4d4d4d';
                 }
             }
             function changeposition(){
                 for(let i=;i<textset.length;i++){
                     for(let j=0;j<textset[i][1].length;j++){
                         let tempx=textset[i][1][j].offsetleft+"px";
                         let tempy=textset[i][1][j].offsettop+"px";
                         settimeout(function(){
                             textset[i][][j].style.position="absolute";
                             textset[i][1][j].style.left=tempx;textset[i][1][j].style.top=tempy;
                         },50);
                      }
                  }
             }
             function changecircle(){
                 iscircle=true;
                 clock.style.transform="rotate(90deg)";
             }
         </script>
     </body>
 </html>

效果:

HTML 罗盘式时钟的实现

到此这篇关于html 罗盘式时钟的实现的文章就介绍到这了,更多相关html 罗盘式时钟内容请搜索以前的文章或继续浏览下面的相关文章,希望大家以后多多支持!