濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > 會(huì)走動(dòng)的圖形html5時(shí)鐘示例

會(huì)走動(dòng)的圖形html5時(shí)鐘示例

熱門標(biāo)簽:百度地圖標(biāo)注為什么總是封號(hào) 地圖標(biāo)注柱狀圖 400開頭的電話好申請(qǐng)不 臨海地圖標(biāo)注app 怎么做百度地圖標(biāo)注 四川移動(dòng)電銷外呼客戶管理系統(tǒng) 智能芯電話機(jī)器人 咸陽(yáng)穩(wěn)定外呼系統(tǒng)軟件 小朱地圖標(biāo)注

使用HTML5制作時(shí)鐘


復(fù)制代碼
代碼如下:

<!DOCTYPE html>
<html>
<head>
<title>html5時(shí)鐘</title>
</head>
<body>
<canvas id = "canvas"></canvas></p> <p> <script>
var Clock = function (canvas, options) {
this.canvas = canvas;
this.ctx = this.canvas.getContext("2d");
this.options = options;
};</p> <p> Clock.prototype = {
constructor: Clock,
drawCircle: function () {
var ctx = this.ctx;
ctx.strokeStyle = "black";
ctx.arc(this.canvas.width / 2, this.canvas.height / 2, 50, 0, 2 * Math.PI, false);
ctx.stroke();
},
drawNum: function () {
var ctx = this.ctx;
var angle = Math.PI * 2 / 12;
for (var i = 1; i <= 12; i += 1) {
ctx.font = "20px Georgia";
ctx.textAlign = "center";
ctx.textBaseline = 'middle';
ctx.fillText(String(i), this.canvas.width / 2 + Math.cos(3 *Math.PI / 2 + angle * i) * 40, this.canvas.height / 2 + Math.sin(3 * Math.PI / 2 + angle * i) * 40);
}
},
drawPointer: function () {
var ctx = this.ctx;
var that = this;
var date, hour, minute, second;
date = new Date();
hour = date.getHours();
if (hour > 12) {
hour = hour % 12;
}
minute = date.getMinutes();
second = date.getSeconds();</p> <p> var b = minute * Math.PI / 30;
var c = second * Math.PI / 30;
var a = hour * Math.PI / 6 + Math.PI / 6 * minute / 60;
var minuteAngle = Math.PI * 2 / 3600;
var secondAngle = Math.PI * 2 / 60;
var hourAngle = Math.PI * 2 / 12 / 3600;</p> <p> ctx.beginPath();
ctx.save();
ctx.translate(that.canvas.width / 2, that.canvas.height / 2);
ctx.arc(0, 0, 3, 0, 2 * Math.PI, false);
ctx.fill();
ctx.closePath();
ctx.beginPath();
a += hourAngle;
ctx.rotate(a);
ctx.fillRect(-2, -22, 4, 30);
ctx.closePath();
ctx.beginPath();
b += minuteAngle;
ctx.rotate(b - a);
ctx.fillRect(-1.5, -26, 3, 35);
ctx.closePath();
ctx.beginPath();
c += secondAngle;
ctx.rotate(c - b);
ctx.fillRect(-1, -30, 2, 40);
ctx.closePath();
ctx.restore();
},
rePaint: function () {
this.drawPointer();
this.drawCircle();
this.drawNum();
},
tik: function () {
var that = this;
var ctx = this.ctx;
this.rePaint();
window.timer = setInterval(function () {
ctx.clearRect(0, 0, that.canvas.width, that.canvas.height);
that.rePaint();
}, 1000);
}
};</p> <p> var options;
var clock = new Clock(document.getElementById("canvas"), options);
clock.tik();
</script>
</body>
</html>


保存后使用瀏覽器運(yùn)行,可以看到走動(dòng)的圓形時(shí)鐘,大家試試看吧

標(biāo)簽:平頂山 公主嶺 黃石 南平 陜西 山南 黃石

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《會(huì)走動(dòng)的圖形html5時(shí)鐘示例》,本文關(guān)鍵詞  會(huì),走動(dòng),的,圖形,html5,時(shí)鐘,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《會(huì)走動(dòng)的圖形html5時(shí)鐘示例》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于會(huì)走動(dòng)的圖形html5時(shí)鐘示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    潜山县| 陇南市| 奇台县| 文水县| 准格尔旗| 睢宁县| 吉安县| 濮阳市| 桐城市| 麻阳| 于都县| 大石桥市| 亚东县| 浦江县| 荥经县| 马边| 大厂| 孟连| 望都县| 全椒县| 青州市| 庄浪县| 德庆县| 宾川县| 彝良县| 资中县| 香港| 永春县| 晋州市| 泸西县| 神农架林区| 万山特区| 化州市| 嫩江县| 雷山县| 当涂县| 清镇市| 山阴县| 乌拉特中旗| 民乐县| 霍城县|