成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

js計(jì)時(shí)事件實(shí)現(xiàn)圓形時(shí)鐘-創(chuàng)新互聯(lián)

本文實(shí)例為大家分享了js圓形時(shí)鐘效果的具體代碼,供大家參考,具體內(nèi)容如下

目前創(chuàng)新互聯(lián)已為上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、謝通門(mén)網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶(hù)導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶(hù)和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。

js計(jì)時(shí)事件實(shí)現(xiàn)圓形時(shí)鐘

代碼:

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8"/>
 <title>時(shí)鐘</title>
 <style>
 *{margin: 0; padding: 0;}

 div.dd{
  margin: 0 auto;
  width: 400px;
  padding-top: 100px;
 }
 </style>
</head>
<body>
<div class="dd">
 <canvas id="clock" height="400px" width="400px">你的瀏覽器不支持canvas</canvas>
</div>
<script type="text/javascript">
 (function(doc){
 var can = doc.getElementById("clock");
 var con = can.getContext("2d");//創(chuàng)建一個(gè)2d上下文
 con.translate(200, 200);//重新確定坐標(biāo)原點(diǎn)(確定圓心位置)
 
 //外圓
 con.beginPath();
 con.fillStyle = '#fff';
 con.arc(0, 0, 200, 0, Math.PI*2, false);
 con.fill();
 
 //內(nèi)圓
 con.beginPath();
 con.fillStyle = '#aaa';
 con.arc(0, 0, 195, 0, Math.PI*2, false);
 con.fill();
 
 //繪制刻度
 con.beginPath();
 con.font = "bold 20px sans-serif";
 con.textAlign = "center";
 con.textBaseline = "middle"
 con.fillStyle = '#000000';
 con.fillText("12", 0, -170);
 con.fillText("3",170,0);
 con.fillText("6",0,170);
 con.fillText("9",-170,0);
 con.fillText("1",84,-147.224);
 con.fillText("2",147.224,-84);
 con.fillText("4",147.224,84);
 con.fillText("5",84,147.224);
 con.fillText("7",-84,147.224);
 con.fillText("8",-147.224,84);
 con.fillText("10",-147.224,-84);
 con.fillText("11",-84,-147.224);
 
 //獲取當(dāng)前時(shí)間
 var d = new Date(), time ={};
 time.H = d.getHours()%12;
 time.M = d.getMinutes();
 time.S = d.getSeconds();
 
 function getTime(){
  time.S++;
  if(time.S > 59){
  time.S = 0;
  time.M++;
  if(time.M > 60){
   time.M = 0;
   time.H++;
   if(time.H > 11){
   time.H = 0;
   }
  }
  }
  canvasTimeLine();
 }
 
 //將角度轉(zhuǎn)為弧度
 function numToDeg(num){
  return ((num*6 - 90)*0.0174444444444444);
 
 }
 //確定刻度位置
 function computePositionByLenDeg(len, deg){
  return {
  x: len*Math.cos(deg),
  y: len*Math.sin(deg)
  }
 }
 //繪制刻度
 function canvasLineMintus(){
  for(var i = 0;i<60; i++){
  var rec = 180;
  con.beginPath();
  con.lineWidth = 4;
  if(i%5 != 0){
   con.lineWidth = 1;
   rec = 184
  }
 
  var beinDeg = numToDeg(i),
   beginPot = computePositionByLenDeg(rec, beinDeg),
   endPot = computePositionByLenDeg(190, beinDeg);
  con.moveTo(beginPot.x, beginPot.y);
  con.lineTo(endPot.x, endPot.y);
  con.stroke();
  }
 }
 
 function canvasTimeLine(){
  var sDeg = numToDeg(time.S),
   mDeg = numToDeg(time.M),
   hDeg = numToDeg(time.H*5 + Math.floor(time.M/12)),
   sPot = computePositionByLenDeg(150, sDeg),
   mPot = computePositionByLenDeg(135, mDeg),
   hPot = computePositionByLenDeg(110, hDeg);
 
  //時(shí)鐘表面
  con.beginPath();
  con.fillStyle = '#ddd';
  con.arc(0, 0, 156, 0, Math.PI*2, false);
  con.fill();
 
 
 
  //時(shí)針
  con.beginPath();
  con.moveTo(0, 0);
  con.lineTo(hPot.x, hPot.y);
  con.lineWidth = 6;
  con.strokeStyle = "#333";
  con.stroke();
 
  //分針
  con.beginPath();
  con.moveTo(0, 0);
  con.lineTo(mPot.x, mPot.y);
  con.lineWidth = 4;
  con.strokeStyle = "#333";
  con.stroke();
 
  //秒針
  con.beginPath();
  con.moveTo(0, 0);
  con.lineTo(sPot.x, sPot.y);
  con.lineWidth = 2;
  con.strokeStyle = "#ff0000";
  con.stroke();
 
  //針心
  con.beginPath();
  con.fillStyle = '#aaaaaa';
  con.arc(0, 0, 8, 0, Math.PI*2, false);
  con.fill();
  con.beginPath();
  con.fillStyle = '#f00';
  con.arc(0, 0, 4, 0, Math.PI*2, false);
  con.fill();
 
 }
 canvasLineMintus();
 getTime();
 
 setInterval(getTime, 1000);
 
 })(document);
</script>
</body>
</html>

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。

網(wǎng)站標(biāo)題:js計(jì)時(shí)事件實(shí)現(xiàn)圓形時(shí)鐘-創(chuàng)新互聯(lián)
鏈接分享:http://jinyejixie.com/article4/csoiie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、品牌網(wǎng)站建設(shè)、面包屑導(dǎo)航、電子商務(wù)、小程序開(kāi)發(fā)、移動(dòng)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(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)站
湘潭市| 滨州市| 长寿区| 昌图县| 纳雍县| 阿图什市| 饶阳县| 孝昌县| 宁津县| 荣昌县| 邵东县| 辉县市| 盱眙县| 永德县| 如东县| 林西县| 永仁县| 高平市| 巩义市| 藁城市| 始兴县| 衡水市| 福安市| 抚松县| 南乐县| 麦盖提县| 郎溪县| 晋宁县| 安阳市| 宜君县| 北辰区| 介休市| 翁牛特旗| 栾川县| 密山市| 鹤山市| 贵定县| 台江县| 泾源县| 华阴市| 临沂市|