html5怎么制作時(shí)鐘動(dòng)畫-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“html5怎么制作時(shí)鐘動(dòng)畫”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

10年積累的成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有江夏免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

<canvas id="clock" width="500" height="500" style="background-color: yellow"></canvas>

代碼如下:


var clock=document.getElementById("clock");
   var cxt=clock.getContext("2d");
function drawNow(){
   var now=new Date();
   var hour=now.getHours();
   var min=now.getMinutes();
   var sec=now.getSeconds();
   hour=hour>12?hour-12:hour;
   hour=hour+min/60;
   //表盤(藍(lán)色)
   cxt.lineWidth=10;
   cxt.strokeStyle="blue"
   cxt.beginPath();
   cxt.arc(250,250,200,0,360,false);
   cxt.closePath();
   cxt.stroke();
   //刻度
   //時(shí)刻度
   for(var i=0;i<12;i++){
       cxt.save();
       cxt.lineWidth=7;
       cxt.strokeStyle="black";
       cxt.translate(250,250);
       cxt.rotate(i*30*Math.PI/180);//旋轉(zhuǎn)角度  角度*Math.PI/180=弧度
       cxt.beginPath();
       cxt.moveTo(0,-170);
       cxt.lineTo(0,-190);
       cxt.closePath();
       cxt.stroke();
       cxt.restore();
   }
   //分刻度
   for(var i=0;i<60;i++){
       cxt.save();
       //設(shè)置分刻度的粗細(xì)
       cxt.lineWidth=5;
       //重置畫布原點(diǎn)
       cxt.translate(250,250);
       //設(shè)置旋轉(zhuǎn)角度
       cxt.rotate(i*6*Math.PI/180);
       //畫分針刻度
       cxt.strokeStyle="black";
       cxt.beginPath();
       cxt.moveTo(0,-180);
       cxt.lineTo(0,-190);
       cxt.closePath();
       cxt.stroke();
       cxt.restore();
   }
   //時(shí)針
   cxt.save();
   // 設(shè)置時(shí)針風(fēng)格
   cxt.lineWidth=7;
   cxt.strokeStyle="black";
   cxt.translate(250,250);
   cxt.rotate(hour*30*Math.PI/180);
   cxt.beginPath();
   cxt.moveTo(0,-140);
   cxt.lineTo(0,10);
   cxt.closePath();
   cxt.stroke();
   cxt.restore();
   //分針
   cxt.save();
   cxt.lineWidth=5;
   cxt.strokeStyle="black";
   //設(shè)置異次元空間分針畫布的中心
   cxt.translate(250,250);
   cxt.rotate(min*6*Math.PI/180);
   cxt.beginPath();
   cxt.moveTo(0,-160);
   cxt.lineTo(0,15);
   cxt.closePath();
   cxt.stroke()
   cxt.restore();
   //秒針
   cxt.save();
   //設(shè)置秒針的風(fēng)格
   //顏色:紅色
   cxt.strokeStyle="red";
   cxt.lineWidth=3;
   //重置原點(diǎn)
   cxt.translate(250,250);
   //設(shè)置角度
   //cxt.rotate(330*Math.PI/180);
   cxt.rotate(sec*6*Math.PI/180);
   cxt.beginPath();
   cxt.moveTo(0,-170);
   cxt.lineTo(0,20);
   cxt.closePath();
   cxt.stroke();
   //畫出時(shí)針,分針,秒針的交叉點(diǎn)
   cxt.beginPath();
   cxt.arc(0,0,5,0,360,false);
   cxt.closePath();
   //設(shè)置填充
   cxt.fillStyle="gray";
   cxt.fill();
   //cxt.strokeStyle="red";
   cxt.stroke();
   //畫出秒針的小圓點(diǎn)
   cxt.beginPath();
   cxt.arc(0,-140,5,0,360,false);
   cxt.closePath();
   //設(shè)置填充
   cxt.fillStyle="gray";
   cxt.fill();
   //cxt.strokeStyle="red";
   cxt.stroke();</p> <p>    cxt.restore();</p> <p>}
function drawClock(){
   cxt.clearRect(0,0,500,500);
   drawNow();
}
   drawNow();
   setInterval(drawClock,1000);


html5怎么制作時(shí)鐘動(dòng)畫

“html5怎么制作時(shí)鐘動(dòng)畫”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

本文名稱:html5怎么制作時(shí)鐘動(dòng)畫-創(chuàng)新互聯(lián)
當(dāng)前網(wǎng)址:http://bm7419.com/article0/dgdpio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、全網(wǎng)營(yíng)銷推廣建站公司、網(wǎng)站策劃、商城網(wǎng)站用戶體驗(yàn)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)