首頁 >web前端 >H5教程 >會走動的圖形html5時鐘範例_html5教學技巧

會走動的圖形html5時鐘範例_html5教學技巧

WBOY
WBOY原創
2016-05-16 15:48:011462瀏覽

使用HTML5製作時鐘


複製程式碼
程式碼如下:






html5時鐘


this this this this this this 看到.options = 選項;
};

Clock.prototype = {
建構子: Clock,
drawCircle: function () {
var ctx = this.ctx;
ctx.tripStyle = "black";
ctx .arc(this .canvas.width / 2, this.canvas.height / 2, 50, 0, 2 * Math.PI, false);
ctx.lines();
},
drawNum : function () {
var ctx = this.ctx;
var 角度= Math.PI * 2 / 12;
for (var i = 1; i ctx .font = "20px Georgia";
ctx.textAlign = "center";
ctx.textBaseline = 'middle';
ctx.fillText(String(i), .canvas.widthth. / 2 Math .cos(3 *Math.PI / 2 角度* i) * 40, this.canvas.height / 2 Math.sin(3 * Math.PI / 2 角度* i) * 40);
}
},
drawPointer: function () {
var ctx = this.ctx;
var that = this;
var 日期、小時、分鐘、秒;
date = new Date() ;
小時= date.getHours();
if (小時>; 12) {
小時= 小時% 12;
}
分鐘= date.getMinutes();
秒= date.getSeconds();

var b = 分* Math.PI / 30;
var c = 秒* Math.PI / 30;
var a = 小時* Math.PI / 6 Math.PI / 6 * 分/ 60 ;
var 分鐘角度= Math.PI * 2 / 3600;
var secondaryAngle = Math.PI * 2 / 60;
var hourAngle = Math.PI * 2 / 12 / 3600;

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 = 分鐘角度;
ctx.rotate(b - a);
ctx.fillRect(-1.5, -26, 3, 35);
ctx.closePath();
ctx.beginPath( );
c = secondaryAngle;
ctx.rotate(c - b);
ctx.fillRect(-1, -30, 2, 40);
ctx.closePath();
ctx.restore ();
},
rePaint: function () {
this.drawPointer();
this.drawCircle();
this.drawNum(); 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);
}
}
};

var options;
var Clock = new Clock(document.getElementById("canvas"), options);
clock.tik();



陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn