css3和原生js時鐘

來源:互聯網
上載者:User

標籤:bottom   sha   20px   doc   top   body   text   otto   lan   

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title>    <style>    div{        width:200px;        height:200px;        border-radius: 50%;        border:1px solid #000;        position: relative;        margin:5px auto;        text-align: center;        box-shadow: 0px 0px 20px 5px #000;    }    div span{        transform-origin: bottom center;    }    .sec{        position: absolute;        top:50%;        left:50%;        margin-left:-2px;        margin-top:-80px;        height:80px;        width:4px;        background: red;        border-radius: 50% 50% 0 0;    }    .min{        position: absolute;        top:50%;        left:50%;        margin-left:-3px;        margin-top:-60px;        height:60px;        width:6px;        background: #000;        border-radius: 50% 50% 0 0;    }    .hou{        position: absolute;        top:50%;        left:50%;        margin-left:-4px;        margin-top:-40px;        height:40px;        width:8px;        background: #000;        border-radius: 50% 50% 0 0;    }    .cap{        position: absolute;        top:50%;        left:50%;        margin-left:-6px;        margin-top:-6px;        height:12px;        width:12px;        background: radial-gradient(#ccc,#999);        border-radius: 50%;    }    i b{        position: absolute;        top:12px;        left:-4px;    }    </style>    <script>    window.onload=function(){        var aSpan=document.querySelectorAll(‘span‘);        var oBox=document.getElementById(‘box‘);        clock();        setInterval(clock,30);        for (var i = 0; i <60; i++) {            var oI=document.createElement(‘i‘);            oI.style.width=‘6px‘;            if(i%5){                oI.style.height=‘8px‘;            }else{                oI.innerHTML=‘<b>‘+i/5+‘</b>‘;                oI.children[0].style.transform=‘rotate(-‘+i*6+‘deg)‘;                oI.style.height=‘16px‘;            }                        oI.style.position=‘absolute‘;            oI.style.top=‘0px‘;            oI.style.left=‘100px‘;            oI.style.background=‘#000‘;            oI.style.transform=‘rotate(‘+i*6+‘deg)‘;            oI.style.transformOrigin=‘0px 100px‘;            oBox.appendChild(oI);        }        function clock(){            var oDate=new Date();            var h=oDate.getHours();            var m=oDate.getMinutes();            var s=oDate.getSeconds();            var ms=oDate.getMilliseconds();                        aSpan[2].style.transform=‘rotate(‘+(360*(h%12)/12+m*30/60)+‘deg)‘;            aSpan[1].style.transform=‘rotate(‘+(360*m/60+s*6/60)+‘deg)‘;            aSpan[0].style.transform=‘rotate(‘+(360*s/60+ms*6/1000)+‘deg)‘;        }    };    </script></head><body>    <div id="box">        <span class="sec"></span>        <span class="min"></span>        <span class="hou"></span>        <p class="cap"></p>    </div></body></html>

 

css3和原生js時鐘

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.