canvas實現的圓形鐘錶效果程式碼例項
本章節分享一段程式碼例項,它利用canvas實現了圓形鐘錶效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style> body { background: black; } #c1 { background: white; } </style> <script> window.onload = function () { var oC = document.getElementById('c1'); 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 oHours = oDate.getHours(); var oMin = oDate.getMinutes(); var oSen = oDate.getSeconds(); var oHoursValue = (-90 + oHours * 30 + oMin / 2) * Math.PI / 180; var oMinValue = (-90 + oMin * 6) * Math.PI / 180; var oSenValue = (-90 + oSen * 6) * Math.PI / 180; oGC.beginPath(); for (var 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 = 'white'; oGC.beginPath(); oGC.moveTo(x, y); oGC.arc(x, y, r * 19 / 20, 0, 360 * (i + 1) * Math.PI / 180, false); oGC.closePath(); oGC.fill(); oGC.lineWidth = 3; oGC.beginPath(); for (var 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 = 'white'; oGC.beginPath(); oGC.moveTo(x, y); oGC.arc(x, y, r * 18 / 20, 0, 360 * (i + 1) * Math.PI / 180, false); oGC.closePath(); oGC.fill(); oGC.lineWidth = 5; oGC.beginPath(); oGC.moveTo(x, y); oGC.arc(x, y, r * 10 / 20, oHoursValue, oHoursValue, false); oGC.closePath(); oGC.stroke(); oGC.lineWidth = 3; oGC.beginPath(); oGC.moveTo(x, y); oGC.arc(x, y, r * 14 / 20, oMinValue, oMinValue, false); oGC.closePath(); oGC.stroke(); oGC.lineWidth = 1; oGC.beginPath(); oGC.moveTo(x, y); oGC.arc(x, y, r * 19 / 20, oSenValue, oSenValue, false); oGC.closePath(); oGC.stroke(); } setInterval(toDraw, 1000); toDraw(); }; </script> </head> <body> <canvas id="c1" width="400" height="400"></canvas> </body> </html>
相關文章
- canvas繪製圓形鐘錶程式碼例項Canvas
- canvas實現的圓形走動鐘錶效果Canvas
- javascript圓形電子鐘錶效果程式碼例項JavaScript
- css3和js實現的圓形鐘錶效果程式碼例項CSSS3JS
- javascript圓形鐘錶程式碼例項JavaScript
- canvas原型鐘錶效果程式碼例項Canvas原型
- jquery自動走動的圓形鐘錶效果程式碼例項jQuery
- canvas繪製鐘錶效果程式碼例項Canvas
- canvas實現的圓形時鐘效果Canvas
- canvas實現的鐘表效果程式碼例項Canvas
- css實現圓形、橢圓和半圓效果程式碼例項CSS
- jquery和css實現的圓形鐘錶效果jQueryCSS
- canvas實現的動態心形效果程式碼例項Canvas
- canvas繪製實心圓形程式碼例項Canvas
- SVG圓形鐘錶效果SVG
- JavaScript圓形鐘錶效果JavaScript
- js鐘錶效果程式碼例項JS
- canvas圓形時鐘效果Canvas
- js和css3實現的圓形鐘錶效果JSCSSS3
- canvas繪製橢圓效果程式碼例項Canvas
- canvas實現的多邊形程式碼例項Canvas
- canvas實現的鋸齒效果程式碼例項Canvas
- canvas實現的驗證碼效果程式碼例項Canvas
- 利用canvas實現的驗證碼效果程式碼例項Canvas
- canvas實現的雪花飄落效果程式碼例項Canvas
- canvas實現的藍色雨滴效果程式碼例項Canvas
- canvas實現的彈力小球效果程式碼例項Canvas
- canvas實現煙花燃放效果程式碼例項Canvas
- canvas繪製圓盤走動鐘錶效果Canvas
- html5利用canvas圓形和多邊形程式碼例項HTMLCanvas
- css3實現的圓角效果程式碼例項CSSS3
- canvas實現的七巧板效果程式碼例項Canvas
- canvas實現的簡單畫板效果程式碼例項Canvas
- JavaScript動態圓形鐘錶效果詳解JavaScript
- css3動態圓形鐘錶效果CSSS3
- CSS3 實現的鐘表效果程式碼例項CSSS3
- canvas火焰效果程式碼例項Canvas
- CSS3實現的div圓角效果程式碼例項CSSS3