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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

html网页静态时钟代码,网页时钟实现代码html5

發布時間:2023/12/14 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html网页静态时钟代码,网页时钟实现代码html5 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

canvas{position:absolute;top:0px;left:0px;}

時鐘

//獲取繪圖對象

var canvas = document.getElementById('canvas');

var context = canvas.getContext('2d');

var p_canvas = document.getElementById('p_canvas');

var p_context = p_canvas.getContext('2d');

var height=200,width=200;

//畫大圓

context.beginPath();

context.strokeStyle="#009999";

context.arc(width/2,height/2,width/2-1,0,Math.PI*2,true);

context.stroke();

context.closePath();

//畫中間點

context.beginPath();

context.fillStyle="#000";

context.arc(width/2,height/2,3,0,Math.PI*2,true);

context.fill();

context.closePath();

//畫小刻度

var angle = 0,radius = width/2 - 4;

for(var i=0;i<60;i++){

context.beginPath();

context.strokeStyle="#000";

//確認刻度的起始點

var x = width/2 + radius*Math.cos(angle),y = height/2 + radius*Math.sin(angle);

context.moveTo(x,y);

//這里是用來將刻度的另一點指向中心點,并給予正確的角度

//PI是180度,正確的角度就是 angle+180度,正好相反方向

var temp_angle = Math.PI +angle;

context.lineTo(x +3*Math.cos(temp_angle),y+3*Math.sin(temp_angle));

context.stroke();

context.closePath();

angle+=6/180*Math.PI;

}

//大刻度

angle = 0,radius = width/2 - 4;

context.textBaseline = 'middle';

context.textAlign = 'center';

context.lineWidth = 2;

for(var i=0;i<12;i++){

var num = i+3>12? i+3-12:i+3 ;

context.beginPath();

context.strokeStyle="#FFD700";

var x = width/2 + radius*Math.cos(angle),y = height/2 + radius*Math.sin(angle);

context.moveTo(x,y);

var temp_angle = Math.PI +angle;

context.lineTo(x +8*Math.cos(temp_angle),y+8*Math.sin(temp_angle));

context.stroke();

context.closePath();

//大刻度 文字

context.fillText(num,x+16*Math.cos(temp_angle),y+16*Math.sin(temp_angle));

angle+=30/180*Math.PI;

}

function Pointer(){

var p_type = [['#000',70,1],['#ccc',60,2],['red',50,3]];

function drwePointer(type,angle){

type = p_type[type];

angle = angle*Math.PI*2 - 90/180*Math.PI;

var length= type[1];

p_context.beginPath();

p_context.lineWidth = type[2];

p_context.strokeStyle = type[0];

p_context.moveTo(width/2,height/2);

p_context.lineTo(width/2 + length*Math.cos(angle),height/2 + length*Math.sin(angle));

p_context.stroke();

p_context.closePath();

}

setInterval(function (){

p_context.clearRect(0,0,height,width);

var time = new Date();

var h = time.getHours();

var m = time.getMinutes();

var s = time.getSeconds();

h = h>12?h-12:h;

h = h+m/60;

h=h/12;

m=m/60;

s=s/60;

drwePointer(0,s);

drwePointer(1,m);

drwePointer(2,h);

},500);

}

var p = new Pointer();

做個參考,代碼來源: http://www.php-source.com/article-6390-1.html

總結

以上是生活随笔為你收集整理的html网页静态时钟代码,网页时钟实现代码html5的全部內容,希望文章能夠幫你解決所遇到的問題。

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