質問編集履歴
6
不要なソースコードを削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,106 +1,3 @@
|
|
1
|
-
```ここに言語を入力
|
2
|
-
javascriptのソースコード
|
3
|
-
'use strict';
|
4
|
-
|
5
|
-
(() => {
|
6
|
-
class ClockDrawer {
|
7
|
-
constructor(canvas) {
|
8
|
-
this.ctx = canvas.getContext('2d');
|
9
|
-
this.width = canvas.width;
|
10
|
-
this.height = canvas.height;
|
11
|
-
}
|
12
|
-
|
13
|
-
draw(angle, func) {
|
14
|
-
this.ctx.save();
|
15
|
-
|
16
|
-
this.ctx.translate(this.width / 2, this.height / 2);
|
17
|
-
this.ctx.rotate(Math.PI / 180 * angle);
|
18
|
-
|
19
|
-
this.ctx.beginPath();
|
20
|
-
func(this.ctx);
|
21
|
-
this.ctx.stroke();
|
22
|
-
|
23
|
-
this.ctx.restore();
|
24
|
-
}
|
25
|
-
|
26
|
-
clear() {
|
27
|
-
this.ctx.clearRect(0, 0, this.width, this.height);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
class Clock {
|
32
|
-
constructor(drawer) {
|
33
|
-
this.r = 100;
|
34
|
-
this.drawer = drawer;
|
35
|
-
}
|
36
|
-
|
37
|
-
drawFace() {
|
38
|
-
for (let angle = 0; angle < 360; angle += 6) {
|
39
|
-
this.drawer.draw(angle, ctx => {
|
40
|
-
ctx.moveTo(0, -this.r);
|
41
|
-
if (angle % 30 === 0) {
|
42
|
-
ctx.lineWidth = 2;
|
43
|
-
ctx.lineTo(0, -this.r + 10);
|
44
|
-
ctx.font = '13px Arial';
|
45
|
-
ctx.textAlign = 'center';
|
46
|
-
ctx.fillText(angle / 30 || 12, 0, -this.r + 25);
|
47
|
-
} else {
|
48
|
-
ctx.lineTo(0, -this.r + 5);
|
49
|
-
}
|
50
|
-
});
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
drawHands() {
|
55
|
-
// hour
|
56
|
-
this.drawer.draw(this.h * 30 + this.m * 0.5, ctx => {
|
57
|
-
ctx.lineWidth = 6;
|
58
|
-
ctx.moveTo(0, 10);
|
59
|
-
ctx.lineTo(0, -this.r + 50);
|
60
|
-
});
|
61
|
-
|
62
|
-
// minute
|
63
|
-
this.drawer.draw(this.m * 6, ctx => {
|
64
|
-
ctx.lineWidth = 4;
|
65
|
-
ctx.moveTo(0, 10);
|
66
|
-
ctx.lineTo(0, -this.r + 30);
|
67
|
-
});
|
68
|
-
|
69
|
-
// second
|
70
|
-
this.drawer.draw(this.s * 6, ctx => {
|
71
|
-
ctx.strokeStyle = 'red';
|
72
|
-
ctx.moveTo(0, 20);
|
73
|
-
ctx.lineTo(0, -this.r + 20);
|
74
|
-
});
|
75
|
-
}
|
76
|
-
|
77
|
-
update() {
|
78
|
-
this.h = (new Date()).getHours();
|
79
|
-
this.m = (new Date()).getMinutes();
|
80
|
-
this.s = (new Date()).getSeconds();
|
81
|
-
}
|
82
|
-
|
83
|
-
run() {
|
84
|
-
this.update();
|
85
|
-
|
86
|
-
this.drawer.clear();
|
87
|
-
this.drawFace();
|
88
|
-
this.drawHands();
|
89
|
-
|
90
|
-
setTimeout(() => {
|
91
|
-
this.run();
|
92
|
-
}, 100);
|
93
|
-
}
|
94
|
-
}
|
95
|
-
|
96
|
-
const canvas = document.querySelector('canvas');
|
97
|
-
if (typeof canvas.getContext === 'undefined') {
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
|
101
|
-
const clock = new Clock(new ClockDrawer(canvas));
|
102
|
-
clock.run();
|
103
|
-
})();
|
104
1
|
```超超初心者です。難しいプログラミング用語は分かりません…。
|
105
2
|
wordpressでブログを作成しています。(テーマはcocoon)
|
106
3
|
サイドバーのカスタムHTMLにHTMLとjavascriptを記述して、アナログ時計(ソースコードはドットインストールの完全コピペです)を表示させようとしましたが、領域だけ真っ白に表示されただけで肝心の時計が表示されません。
|
5
ご追記の削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -114,6 +114,4 @@
|
|
114
114
|
|
115
115
|

|
116
116
|
|
117
|
-

|
117
|
+

|
118
|
-
|
119
|
-
[サイトURL](https://japan-thinks.com)
|
4
サイトのURLの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -114,4 +114,6 @@
|
|
114
114
|
|
115
115
|

|
116
116
|
|
117
|
-

|
117
|
+

|
118
|
+
|
119
|
+
[サイトURL](https://japan-thinks.com)
|
3
codeを<code>タグで挿入しなおしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
```ここに言語を入力
|
1
2
|
javascriptのソースコード
|
2
3
|
'use strict';
|
3
4
|
|
@@ -100,9 +101,6 @@
|
|
100
101
|
const clock = new Clock(new ClockDrawer(canvas));
|
101
102
|
clock.run();
|
102
103
|
})();
|
103
|
-
|
104
|
-
```ここに言語を入力
|
105
|
-
コード
|
106
104
|
```超超初心者です。難しいプログラミング用語は分かりません…。
|
107
105
|
wordpressでブログを作成しています。(テーマはcocoon)
|
108
106
|
サイドバーのカスタムHTMLにHTMLとjavascriptを記述して、アナログ時計(ソースコードはドットインストールの完全コピペです)を表示させようとしましたが、領域だけ真っ白に表示されただけで肝心の時計が表示されません。
|
2
codeを<code>タグで挿入しなおしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,118 +1,119 @@
|
|
1
|
+
javascriptのソースコード
|
1
|
-
|
2
|
+
'use strict';
|
2
|
-
wordpressでブログを作成しています。(テーマはcocoon)
|
3
|
-
サイドバーのカスタムHTMLにHTMLとjavascriptを記述して、アナログ時計(ソースコードはドットインストールの完全コピペです)を表示させようとしましたが、領域だけ真っ白に表示されただけで肝心の時計が表示されません。
|
4
|
-
そもそも、カスタムHTMLにjavascriptを記述することはシステム上不可能なのでしょうか?
|
5
3
|
|
4
|
+
(() => {
|
5
|
+
class ClockDrawer {
|
6
|
+
constructor(canvas) {
|
6
|
-
|
7
|
+
this.ctx = canvas.getContext('2d');
|
8
|
+
this.width = canvas.width;
|
9
|
+
this.height = canvas.height;
|
10
|
+
}
|
7
11
|
|
8
|
-
|
12
|
+
draw(angle, func) {
|
13
|
+
this.ctx.save();
|
9
14
|
|
15
|
+
this.ctx.translate(this.width / 2, this.height / 2);
|
10
|
-
|
16
|
+
this.ctx.rotate(Math.PI / 180 * angle);
|
11
17
|
|
12
|
-
|
18
|
+
this.ctx.beginPath();
|
19
|
+
func(this.ctx);
|
20
|
+
this.ctx.stroke();
|
13
21
|
|
14
|
-
|
22
|
+
this.ctx.restore();
|
23
|
+
}
|
15
24
|
|
25
|
+
clear() {
|
26
|
+
this.ctx.clearRect(0, 0, this.width, this.height);
|
27
|
+
}
|
28
|
+
}
|
16
29
|
|
17
|
-
|
30
|
+
class Clock {
|
18
|
-
|
31
|
+
constructor(drawer) {
|
32
|
+
this.r = 100;
|
33
|
+
this.drawer = drawer;
|
34
|
+
}
|
19
35
|
|
20
|
-
(
|
36
|
+
drawFace() {
|
37
|
+
for (let angle = 0; angle < 360; angle += 6) {
|
38
|
+
this.drawer.draw(angle, ctx => {
|
39
|
+
ctx.moveTo(0, -this.r);
|
21
|
-
|
40
|
+
if (angle % 30 === 0) {
|
22
|
-
|
41
|
+
ctx.lineWidth = 2;
|
42
|
+
ctx.lineTo(0, -this.r + 10);
|
43
|
+
ctx.font = '13px Arial';
|
23
|
-
|
44
|
+
ctx.textAlign = 'center';
|
24
|
-
|
45
|
+
ctx.fillText(angle / 30 || 12, 0, -this.r + 25);
|
46
|
+
} else {
|
25
|
-
|
47
|
+
ctx.lineTo(0, -this.r + 5);
|
26
|
-
|
48
|
+
}
|
49
|
+
});
|
50
|
+
}
|
51
|
+
}
|
27
52
|
|
28
|
-
|
53
|
+
drawHands() {
|
54
|
+
// hour
|
55
|
+
this.drawer.draw(this.h * 30 + this.m * 0.5, ctx => {
|
56
|
+
ctx.lineWidth = 6;
|
29
|
-
|
57
|
+
ctx.moveTo(0, 10);
|
58
|
+
ctx.lineTo(0, -this.r + 50);
|
59
|
+
});
|
30
60
|
|
31
|
-
|
61
|
+
// minute
|
32
|
-
|
62
|
+
this.drawer.draw(this.m * 6, ctx => {
|
63
|
+
ctx.lineWidth = 4;
|
64
|
+
ctx.moveTo(0, 10);
|
65
|
+
ctx.lineTo(0, -this.r + 30);
|
66
|
+
});
|
33
67
|
|
68
|
+
// second
|
69
|
+
this.drawer.draw(this.s * 6, ctx => {
|
70
|
+
ctx.strokeStyle = 'red';
|
34
|
-
|
71
|
+
ctx.moveTo(0, 20);
|
35
|
-
|
72
|
+
ctx.lineTo(0, -this.r + 20);
|
36
|
-
|
73
|
+
});
|
74
|
+
}
|
37
75
|
|
76
|
+
update() {
|
38
|
-
|
77
|
+
this.h = (new Date()).getHours();
|
78
|
+
this.m = (new Date()).getMinutes();
|
79
|
+
this.s = (new Date()).getSeconds();
|
39
|
-
|
80
|
+
}
|
40
81
|
|
41
|
-
|
82
|
+
run() {
|
42
|
-
|
83
|
+
this.update();
|
43
|
-
}
|
44
|
-
}
|
45
84
|
|
46
|
-
class Clock {
|
47
|
-
constructor(drawer) {
|
48
|
-
this.r = 100;
|
49
|
-
|
85
|
+
this.drawer.clear();
|
50
|
-
|
86
|
+
this.drawFace();
|
87
|
+
this.drawHands();
|
51
88
|
|
52
|
-
drawFace() {
|
53
|
-
for (let angle = 0; angle < 360; angle += 6) {
|
54
|
-
|
89
|
+
setTimeout(() => {
|
55
|
-
ctx.moveTo(0, -this.r);
|
56
|
-
if (angle % 30 === 0) {
|
57
|
-
ctx.lineWidth = 2;
|
58
|
-
|
90
|
+
this.run();
|
59
|
-
ctx.font = '13px Arial';
|
60
|
-
ctx.textAlign = 'center';
|
61
|
-
ctx.fillText(angle / 30 || 12, 0, -this.r + 25);
|
62
|
-
|
91
|
+
}, 100);
|
63
|
-
ctx.lineTo(0, -this.r + 5);
|
64
|
-
|
92
|
+
}
|
65
|
-
});
|
66
|
-
|
93
|
+
}
|
67
|
-
}
|
68
|
-
|
69
|
-
drawHands() {
|
70
|
-
// hour
|
71
|
-
this.drawer.draw(this.h * 30 + this.m * 0.5, ctx => {
|
72
|
-
ctx.lineWidth = 6;
|
73
|
-
ctx.moveTo(0, 10);
|
74
|
-
ctx.lineTo(0, -this.r + 50);
|
75
|
-
});
|
76
94
|
|
77
|
-
|
95
|
+
const canvas = document.querySelector('canvas');
|
78
|
-
|
96
|
+
if (typeof canvas.getContext === 'undefined') {
|
79
|
-
|
97
|
+
return;
|
80
|
-
ctx.moveTo(0, 10);
|
81
|
-
ctx.lineTo(0, -this.r + 30);
|
82
|
-
|
98
|
+
}
|
83
99
|
|
84
|
-
// second
|
85
|
-
this.drawer.draw(this.s * 6, ctx => {
|
86
|
-
|
100
|
+
const clock = new Clock(new ClockDrawer(canvas));
|
87
|
-
|
101
|
+
clock.run();
|
88
|
-
ctx.lineTo(0, -this.r + 20);
|
89
|
-
|
102
|
+
})();
|
90
|
-
}
|
91
103
|
|
92
|
-
|
104
|
+
```ここに言語を入力
|
105
|
+
コード
|
93
|
-
|
106
|
+
```超超初心者です。難しいプログラミング用語は分かりません…。
|
94
|
-
this.m = (new Date()).getMinutes();
|
95
|
-
|
107
|
+
wordpressでブログを作成しています。(テーマはcocoon)
|
108
|
+
サイドバーのカスタムHTMLにHTMLとjavascriptを記述して、アナログ時計(ソースコードはドットインストールの完全コピペです)を表示させようとしましたが、領域だけ真っ白に表示されただけで肝心の時計が表示されません。
|
96
|
-
|
109
|
+
そもそも、カスタムHTMLにjavascriptを記述することはシステム上不可能なのでしょうか?
|
97
110
|
|
98
|
-
run() {
|
99
|
-
|
111
|
+
※カスタムHTMLのウィジェットでは、html記述内にscriptタグで囲ってjavascriptを記述しています。
|
100
112
|
|
101
|
-
|
113
|
+
※もし、javascriptを反映させることができる場合には、wordpressのウィジェット内に外部ファイルで作成したjavascriptを読み込む方法が有れば併せてご教示お願い申し上げます。
|
102
|
-
this.drawFace();
|
103
|
-
this.drawHands();
|
104
114
|
|
105
|
-
setTimeout(() => {
|
106
|
-
this.run();
|
107
|
-
}, 100);
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
|
-
const canvas = document.querySelector('canvas');
|
112
|
-
|
115
|
+

|
113
|
-
return;
|
114
|
-
}
|
115
116
|
|
116
|
-
|
117
|
+

|
118
|
+
|
117
|
-
|
119
|
+

|
118
|
-
})();
|
1
javascriptのソースコードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,4 +11,108 @@
|
|
11
11
|
|
12
12
|

|
13
13
|
|
14
|
-

|
14
|
+

|
15
|
+
|
16
|
+
|
17
|
+
javascriptのソースコード
|
18
|
+
'use strict';
|
19
|
+
|
20
|
+
(() => {
|
21
|
+
class ClockDrawer {
|
22
|
+
constructor(canvas) {
|
23
|
+
this.ctx = canvas.getContext('2d');
|
24
|
+
this.width = canvas.width;
|
25
|
+
this.height = canvas.height;
|
26
|
+
}
|
27
|
+
|
28
|
+
draw(angle, func) {
|
29
|
+
this.ctx.save();
|
30
|
+
|
31
|
+
this.ctx.translate(this.width / 2, this.height / 2);
|
32
|
+
this.ctx.rotate(Math.PI / 180 * angle);
|
33
|
+
|
34
|
+
this.ctx.beginPath();
|
35
|
+
func(this.ctx);
|
36
|
+
this.ctx.stroke();
|
37
|
+
|
38
|
+
this.ctx.restore();
|
39
|
+
}
|
40
|
+
|
41
|
+
clear() {
|
42
|
+
this.ctx.clearRect(0, 0, this.width, this.height);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
class Clock {
|
47
|
+
constructor(drawer) {
|
48
|
+
this.r = 100;
|
49
|
+
this.drawer = drawer;
|
50
|
+
}
|
51
|
+
|
52
|
+
drawFace() {
|
53
|
+
for (let angle = 0; angle < 360; angle += 6) {
|
54
|
+
this.drawer.draw(angle, ctx => {
|
55
|
+
ctx.moveTo(0, -this.r);
|
56
|
+
if (angle % 30 === 0) {
|
57
|
+
ctx.lineWidth = 2;
|
58
|
+
ctx.lineTo(0, -this.r + 10);
|
59
|
+
ctx.font = '13px Arial';
|
60
|
+
ctx.textAlign = 'center';
|
61
|
+
ctx.fillText(angle / 30 || 12, 0, -this.r + 25);
|
62
|
+
} else {
|
63
|
+
ctx.lineTo(0, -this.r + 5);
|
64
|
+
}
|
65
|
+
});
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
drawHands() {
|
70
|
+
// hour
|
71
|
+
this.drawer.draw(this.h * 30 + this.m * 0.5, ctx => {
|
72
|
+
ctx.lineWidth = 6;
|
73
|
+
ctx.moveTo(0, 10);
|
74
|
+
ctx.lineTo(0, -this.r + 50);
|
75
|
+
});
|
76
|
+
|
77
|
+
// minute
|
78
|
+
this.drawer.draw(this.m * 6, ctx => {
|
79
|
+
ctx.lineWidth = 4;
|
80
|
+
ctx.moveTo(0, 10);
|
81
|
+
ctx.lineTo(0, -this.r + 30);
|
82
|
+
});
|
83
|
+
|
84
|
+
// second
|
85
|
+
this.drawer.draw(this.s * 6, ctx => {
|
86
|
+
ctx.strokeStyle = 'red';
|
87
|
+
ctx.moveTo(0, 20);
|
88
|
+
ctx.lineTo(0, -this.r + 20);
|
89
|
+
});
|
90
|
+
}
|
91
|
+
|
92
|
+
update() {
|
93
|
+
this.h = (new Date()).getHours();
|
94
|
+
this.m = (new Date()).getMinutes();
|
95
|
+
this.s = (new Date()).getSeconds();
|
96
|
+
}
|
97
|
+
|
98
|
+
run() {
|
99
|
+
this.update();
|
100
|
+
|
101
|
+
this.drawer.clear();
|
102
|
+
this.drawFace();
|
103
|
+
this.drawHands();
|
104
|
+
|
105
|
+
setTimeout(() => {
|
106
|
+
this.run();
|
107
|
+
}, 100);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
const canvas = document.querySelector('canvas');
|
112
|
+
if (typeof canvas.getContext === 'undefined') {
|
113
|
+
return;
|
114
|
+
}
|
115
|
+
|
116
|
+
const clock = new Clock(new ClockDrawer(canvas));
|
117
|
+
clock.run();
|
118
|
+
})();
|