Skip to content

Commit 0c70b7e

Browse files
committed
サンプルの追加:デジタル時計
1 parent 62b68d3 commit 0c70b7e

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

samples/clock_digital_simple.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<link rel="stylesheet" href="css/base.css">
6+
<script src="https://code.createjs.com/createjs-2015.11.26.min.js"></script>
7+
<script>
8+
window.addEventListener("load", init);
9+
function init() {
10+
// Stageオブジェクトを作成。表示リストのルートになります。
11+
var stage = new createjs.Stage("myCanvas");
12+
13+
// Text インスタンスを作成
14+
var label = new createjs.Text("", "80px sans-serif", "red");
15+
// Text インスタンスは一度だけしか stage に追加しない
16+
stage.addChild(label);
17+
18+
// 時間経過のイベント
19+
createjs.Ticker.addEventListener("tick", handleTick);
20+
function handleTick() {
21+
// 現在時間を取得
22+
var now = new Date();
23+
24+
// 時間の数値を取得
25+
var h = now.getHours(); // 時(0〜23)
26+
var m = now.getMinutes(); // 分(0〜59)
27+
var s = now.getSeconds(); // 秒(0〜59)
28+
29+
// 表示文言を作成
30+
var time = h + ":" + m + ":" + s;
31+
// Text インスタンスの文字列を更新
32+
label.text = time;
33+
34+
// Stageの描画を更新
35+
stage.update();
36+
}
37+
}
38+
</script>
39+
</head>
40+
<body>
41+
<canvas id="myCanvas" width="960" height="540"></canvas>
42+
</body>
43+
</html>

0 commit comments

Comments
 (0)