回答編集履歴

1

修正

2016/11/05 14:36

投稿

退会済みユーザー
test CHANGED
@@ -1,5 +1,139 @@
1
- こちらの回答よく見てください。
1
+ ```html
2
2
 
3
- 同じミスしています。
3
+ <!DOCTYPE html>
4
4
 
5
+ <html lang="ja">
6
+
7
+ <head>
8
+
9
+ <meta charset="UTF-8">
10
+
11
+ <title>信号を作る</title>
12
+
13
+ </head>
14
+
15
+ <body>
16
+
17
+ <div id="square">
18
+
19
+ <div id="red"></div>
20
+
21
+ <div id="yellow"></div>
22
+
23
+ <div id="blue"></div>
24
+
25
+ </div>
26
+
27
+ <button id="start">START</button>
28
+
29
+ <button id="stop">STOP</button>
30
+
31
+
32
+
33
+ <script
34
+
35
+ src="https://code.jquery.com/jquery-3.1.1.slim.js"
36
+
37
+ integrity="sha256-5i/mQ300M779N2OVDrl16lbohwXNUdzL/R2aVUXyXWA="
38
+
39
+ crossorigin="anonymous"></script>
40
+
41
+ <script>
42
+
43
+ var interval; //setintervalとclearintervalつなぐやつ
44
+
45
+
46
+
47
+ //青3秒点灯→3秒点滅→黄色2秒→赤5秒
48
+
49
+
50
+
51
+ //とりあえずボタン押したら青が点灯するプログラム書きます
52
+
53
+ window.onload = function () {
54
+
55
+ var start = document.getElementById('start');
56
+
57
+ start.addEventListener('click', tentou, false);
58
+
59
+ start.addEventListener('click', start_flash, false);
60
+
61
+ };
62
+
63
+
64
+
65
+ function tentou() {
66
+
67
+ var blue = document.getElementById('blue');
68
+
69
+ blue.style.backgroundColor = 'blue';
70
+
71
+ }
72
+
73
+
74
+
75
+ //ボタン押してして三秒後に点滅開始
76
+
77
+ function start_flash() {
78
+
79
+ setTimeout(wait, 3000);
80
+
81
+ function wait() {
82
+
83
+ interval = setInterval(tenmetsu, 500);
84
+
85
+ }
86
+
87
+ }
88
+
89
+ function tenmetsu() {
90
+
91
+ var blue = document.getElementById('blue');
92
+
93
+ if (blue.style.backgroundColor === 'blue') {
94
+
95
+ blue.style.backgroundColor = 'white'
96
+
97
+ } else {
98
+
99
+ blue.style.backgroundColor = "blue"
100
+
101
+ }
102
+
103
+ }
104
+
105
+ //その三秒後(デフォルトから6秒後)点滅終了
106
+
107
+ $('#blue').click(function () {
108
+
109
+ setTimeout(wait, 6000);
110
+
111
+ function wait() {
112
+
113
+ clearInterval(interval);
114
+
115
+ }
116
+
117
+ });
118
+
119
+ //同時に黄色点灯
120
+
121
+ $('#yellow').click(function () {
122
+
123
+ setTimeout(yellow, 6000);
124
+
125
+ function yellow() {
126
+
5
- [https://teratail.com/questions/54023](https://teratail.com/questions/54023)
127
+ $('#yellow').css('background-color', 'yellow');
128
+
129
+ }
130
+
131
+ });
132
+
133
+ </script>
134
+
135
+ </body>
136
+
137
+ </html>
138
+
139
+ ```