html5--canvas繪製簡單的時鐘

來源:互聯網
上載者:User

標籤:cti   支援   script   簡單   head   doc   date()   close   lin   

http://5227788.cn/static/time.html

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title>    <style>    body{background: #131115;}    #c1{background: #fbf7fe;}    </style>    <script>    window.onload=function(){        var oC=document.getElementById(‘c1‘);        var oGC=oC.getContext(‘2d‘);                setInterval(toDraw,1000);        function toDraw(){        var x=200;        var y=200;        var r=150;                            oGC.clearRect(0, 0, oC.width,oC.height);        var oDte=new Date();        var oHours=oDte.getHours();        var oMin=oDte.getMinutes();        var oSen=oDte.getSeconds();            var oHoursValue=(-90+oHours*30+oMin/2)*Math.PI/180;            var oMinValue=(-90+oMin*6)*Math.PI/180;            var oSenValue=(-90+oSen*6)*Math.PI/180;                               oGC.beginPath();        for(var i=0; i<60; i++){                        oGC.moveTo(x,y);            oGC.arc(x,y,r,6*i*Math.PI/180,6*(i+1)*Math.PI/180,false);        }        oGC.closePath();        oGC.stroke();        oGC.fillStyle=‘white‘;        oGC.beginPath();        oGC.moveTo(x,y);        oGC.arc(x,y,r*19/20,0,360*(i+1)*Math.PI/180,false);        oGC.closePath();        oGC.fill();          oGC.lineWidth=3;         oGC.beginPath();                 for(var i=0; i<12; i++){                        oGC.moveTo(x,y);            oGC.arc(x,y,r,30*i*Math.PI/180,30*(i+1)*Math.PI/180,false);        }        oGC.closePath();        oGC.stroke();        oGC.fillStyle=‘white‘;        oGC.beginPath();        oGC.moveTo(x,y);        oGC.arc(x,y,r*18/20,0,360*(i+1)*Math.PI/180,false);        oGC.closePath();        oGC.fill();         oGC.lineWidth=3;          oGC.beginPath();        oGC.moveTo(x,y);        oGC.arc(x,y,r*9/20,oMinValue,oMinValue,false);        oGC.closePath();        oGC.stroke();          oGC.lineWidth=1;        oGC.beginPath();        oGC.moveTo(x,y);        oGC.arc(x,y,r*14/20,oSenValue,oSenValue,false);        oGC.closePath();        oGC.stroke();        oGC.lineWidth=4;          oGC.beginPath();        oGC.moveTo(x,y);        oGC.arc(x,y,r*6/20,oHoursValue,oHoursValue,false);        oGC.closePath();        oGC.stroke();              }        }   </script></head><body>    <canvas id="c1" width="500" height="500"><!-- 預設寬300; 高150 -->    <span>不支援camvas瀏覽器</span>    </canvas></body></html>

 

html5--canvas繪製簡單的時鐘

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.