質問編集履歴

1

コードを書き忘れてました

2018/09/06 23:19

投稿

Kaede0902
Kaede0902

スコア32

test CHANGED
File without changes
test CHANGED
@@ -27,3 +27,199 @@
27
27
 
28
28
 
29
29
  windowLoadのイベント無しでbodyにfunctionも無しでscript直打ちしちゃって大丈夫なんでしょうか??
30
+
31
+
32
+
33
+ MDNのサイトのコードです
34
+
35
+ ```javascript
36
+
37
+ <!DOCTYPE html>
38
+
39
+ <html>
40
+
41
+ <head>
42
+
43
+ <meta charset="utf-8" />
44
+
45
+ <title>Sample of MDN</title>
46
+
47
+ <style>* { padding: 0; margin: 0; }
48
+
49
+ canvas { background: #eee; display:
50
+
51
+ block; margin: 0 auto; }
52
+
53
+ </style>
54
+
55
+ </head>
56
+
57
+ <body>
58
+
59
+
60
+
61
+ <canvas id="myCanvas" width="480" height="320"></canvas>
62
+
63
+
64
+
65
+ <script>
66
+
67
+ var canvas = document.getElementById("myCanvas");
68
+
69
+ var ctx = canvas.getContext("2d");
70
+
71
+ ctx.beginPath();
72
+
73
+ ctx.rect(20, 40, 50, 50);
74
+
75
+ ctx.fillStyle = "#FF0000";
76
+
77
+ ctx.fill();
78
+
79
+ ctx.closePath();
80
+
81
+ ctx.beginPath();
82
+
83
+ ctx.arc(240, 160, 20, 0, Math.PI*2, false);
84
+
85
+ ctx.fillStyle = "green";
86
+
87
+ ctx.fill();
88
+
89
+ ctx.closePath();
90
+
91
+ ctx.beginPath();
92
+
93
+ ctx.rect(160, 10, 100, 40);
94
+
95
+ ctx.strokeStyle = "rgba(0, 0, 255, 0.5)";
96
+
97
+ ctx.stroke();
98
+
99
+ ctx.closePath();
100
+
101
+ </script>
102
+
103
+
104
+
105
+ </body>
106
+
107
+ </html>
108
+
109
+
110
+
111
+ ```
112
+
113
+
114
+
115
+ Oreillyを参考にしたwindowLoadを使う書き方です
116
+
117
+
118
+
119
+ ```javascript
120
+
121
+ <!DOCTYPE html>
122
+
123
+ <html lang="en">
124
+
125
+ <head>
126
+
127
+ <meta charset="UTF-8">
128
+
129
+
130
+
131
+ <title>EX2 seriesMDN</title>
132
+
133
+
134
+
135
+ <style>* { padding: 0; margin: 0; }
136
+
137
+ canvas { background: #eee; display:
138
+
139
+ block; margin: 0 auto; }
140
+
141
+ </style>
142
+
143
+
144
+
145
+ <script >
146
+
147
+ window.addEventListener('load', eventWindowLoaded, false);
148
+
149
+
150
+
151
+ function eventWindowLoaded() {
152
+
153
+ canvasApp();
154
+
155
+ }
156
+
157
+ function canvasApp() {
158
+
159
+ var theCanvas = document.getElementById("canvas");
160
+
161
+ var ctx = theCanvas.getContext("2d");
162
+
163
+ drawScreen();
164
+
165
+ function drawScreen() {
166
+
167
+ ctx.beginPath();
168
+
169
+ ctx.rect(20, 40, 50, 50);
170
+
171
+ ctx.fillStyle = "#FF0000";
172
+
173
+ ctx.fill();
174
+
175
+ ctx.closePath();
176
+
177
+
178
+
179
+ ctx.beginPath();
180
+
181
+ ctx.arc(240, 160, 20, 0, Math.PI*2, false);
182
+
183
+ ctx.fillStyle = "green";
184
+
185
+ ctx.fill();
186
+
187
+ ctx.closePath();
188
+
189
+
190
+
191
+ ctx.beginPath();
192
+
193
+ ctx.rect(160, 10, 100, 40);
194
+
195
+ ctx.strokeStyle = "rgba(0, 0, 255, 0.5)";
196
+
197
+ ctx.stroke();
198
+
199
+ ctx.closePath();
200
+
201
+
202
+
203
+ }
204
+
205
+ }
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+ </script>
214
+
215
+ </head>
216
+
217
+ <body>
218
+
219
+ <canvas id="canvas" width="480" height="320">No canvas sup</canvas>
220
+
221
+ </body>
222
+
223
+ </html>
224
+
225
+ ```