canvas實現(xiàn)鐘表效果
更新時間:2017年02月13日 08:38:20 作者:marie0119
本文主要分享了canvas實現(xiàn)鐘表效果的示例代碼。具有很好的參考價值,下面跟著小編一起來看下吧
效果如下:

代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>canvas畫鐘表</title>
<style>
body{
background: #fc0;
}
#canvas1{
background: #fff;
}
</style>
</head>
<body>
<canvas id="canvas1" width="400" height="400"></canvas>
<script>
var oC=document.getElementById('canvas1');
var oGC=oC.getContext('2d');
function toDraw(){
var x=200;
var y=200;
var r=150;
oGC.clearRect(0,0,oC.width,oC.height);
var oDate=new Date();
var oHour=oDate.getHours();
var oMinu=oDate.getMinutes();
var oSec=oDate.getSeconds();
var hVal=(-90+oHour*30+oMinu/2)*Math.PI/180;
var mVal=(-90+oMinu*6)*Math.PI/180;
var sVal=(-90+oSec*6)*Math.PI/180;
oGC.beginPath();
for(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='#fff';
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*19/20,0,360*Math.PI/180,false);
oGC.closePath();
oGC.fill();
oGC.lineWidth=3;
oGC.beginPath();
for(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='#fff';
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*18/20,0,360*Math.PI/180,false);
oGC.closePath();
oGC.fill();
oGC.lineWidth=5;
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*10/20,hVal,hVal,false);
oGC.closePath();
oGC.stroke();
oGC.lineWidth=3;
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*14/20,mVal,mVal,false);
oGC.closePath();
oGC.stroke();
oGC.lineWidth=1;
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*17/20,sVal,sVal,false);
oGC.closePath();
oGC.stroke();
}
setInterval(toDraw,1000);
toDraw();
</script>
</body>
</html>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
bootstrap制作jsp頁面(根據(jù)值讓table顯示選中)
這篇文章主要為大家詳細(xì)介紹了bootstrap做的jsp頁面,根據(jù)值讓table顯示選中,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01
前端報錯Failed?to?resolve?component:?smile-outlined?If?thi
這篇文章主要為大家介紹了前端報錯?Failed?to?resolve?component:?smile-outlined?If?this?is?a?native?custom?的問題分析解決,有需要的朋友可以借鑒參考下2023-06-06
javascript之通用簡單的table選項卡實現(xiàn)(二)
上篇中的選項卡存在這樣的問題:把邏輯封裝在table.js中,不夠靈活,也就是說如果某個選項卡是實現(xiàn)異步請求或者跳轉(zhuǎn),而非div的顯隱切換,那么就得修過table.js來達到目的,顯然不是我所需要的。2010-05-05
使用layui+ajax實現(xiàn)簡單的菜單權(quán)限管理及排序的方法
今天小編就為大家分享一篇使用layui+ajax實現(xiàn)簡單的菜單權(quán)限管理及排序的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09
JavaScript中判斷整數(shù)的多種方法總結(jié)
這篇文章主要介紹了JavaScript中判斷整數(shù)的多種方法總結(jié),本文總結(jié)了5種判斷整數(shù)的方法,如取余運算符判斷、Math.round、Math.ceil、Math.floor判斷等,需要的朋友可以參考下2014-11-11
javascript實現(xiàn)數(shù)字驗證碼的簡單實例
本篇文章主要是對javascript實現(xiàn)數(shù)字驗證碼的簡單實例進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02

