日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

html5时钟代码菜鸟课程,html5绘制时钟动画

發布時間:2025/3/19 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html5时钟代码菜鸟课程,html5绘制时钟动画 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這篇文章主要介紹了html5繪制時鐘動畫,需要的朋友可以參考下

復制代碼代碼如下:

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;

//表盤(藍色)

cxt.lineWidth=10;

cxt.strokeStyle="blue"

cxt.beginPath();

cxt.arc(250,250,200,0,360,false);

cxt.closePath();

cxt.stroke();

//刻度

//時刻度

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);//旋轉角度 角度*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();

//設置分刻度的粗細

cxt.lineWidth=5;

//重置畫布原點

cxt.translate(250,250);

//設置旋轉角度

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();

}

//時針

cxt.save();

// 設置時針風格

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";

//設置異次元空間分針畫布的中心

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();

//設置秒針的風格

//顏色:紅色

cxt.strokeStyle="red";

cxt.lineWidth=3;

//重置原點

cxt.translate(250,250);

//設置角度

//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();

//畫出時針,分針,秒針的交叉點

cxt.beginPath();

cxt.arc(0,0,5,0,360,false);

cxt.closePath();

//設置填充

cxt.fillStyle="gray";

cxt.fill();

//cxt.strokeStyle="red";

cxt.stroke();

//畫出秒針的小圓點

cxt.beginPath();

cxt.arc(0,-140,5,0,360,false);

cxt.closePath();

//設置填充

cxt.fillStyle="gray";

cxt.fill();

//cxt.strokeStyle="red";

cxt.stroke();

cxt.restore();

}

function drawClock(){

cxt.clearRect(0,0,500,500);

drawNow();

}

drawNow();

setInterval(drawClock,1000);

總結

以上是生活随笔為你收集整理的html5时钟代码菜鸟课程,html5绘制时钟动画的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。