回答編集履歴
1
修正
answer
CHANGED
@@ -1,3 +1,70 @@
|
|
1
|
+
```html
|
2
|
+
<!DOCTYPE html>
|
3
|
+
<html lang="ja">
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
<title>信号を作る</title>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<div id="square">
|
10
|
+
<div id="red"></div>
|
11
|
+
<div id="yellow"></div>
|
12
|
+
<div id="blue"></div>
|
1
|
-
|
13
|
+
</div>
|
14
|
+
<button id="start">START</button>
|
15
|
+
<button id="stop">STOP</button>
|
16
|
+
|
2
|
-
|
17
|
+
<script
|
18
|
+
src="https://code.jquery.com/jquery-3.1.1.slim.js"
|
19
|
+
integrity="sha256-5i/mQ300M779N2OVDrl16lbohwXNUdzL/R2aVUXyXWA="
|
20
|
+
crossorigin="anonymous"></script>
|
21
|
+
<script>
|
22
|
+
var interval; //setintervalとclearintervalつなぐやつ
|
23
|
+
|
24
|
+
//青3秒点灯→3秒点滅→黄色2秒→赤5秒
|
25
|
+
|
26
|
+
//とりあえずボタン押したら青が点灯するプログラム書きます
|
27
|
+
window.onload = function () {
|
28
|
+
var start = document.getElementById('start');
|
29
|
+
start.addEventListener('click', tentou, false);
|
30
|
+
start.addEventListener('click', start_flash, false);
|
31
|
+
};
|
32
|
+
|
33
|
+
function tentou() {
|
34
|
+
var blue = document.getElementById('blue');
|
35
|
+
blue.style.backgroundColor = 'blue';
|
36
|
+
}
|
37
|
+
|
38
|
+
//ボタン押してして三秒後に点滅開始
|
39
|
+
function start_flash() {
|
40
|
+
setTimeout(wait, 3000);
|
41
|
+
function wait() {
|
42
|
+
interval = setInterval(tenmetsu, 500);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
function tenmetsu() {
|
46
|
+
var blue = document.getElementById('blue');
|
47
|
+
if (blue.style.backgroundColor === 'blue') {
|
48
|
+
blue.style.backgroundColor = 'white'
|
49
|
+
} else {
|
50
|
+
blue.style.backgroundColor = "blue"
|
51
|
+
}
|
52
|
+
}
|
53
|
+
//その三秒後(デフォルトから6秒後)点滅終了
|
54
|
+
$('#blue').click(function () {
|
55
|
+
setTimeout(wait, 6000);
|
56
|
+
function wait() {
|
57
|
+
clearInterval(interval);
|
58
|
+
}
|
59
|
+
});
|
60
|
+
//同時に黄色点灯
|
61
|
+
$('#yellow').click(function () {
|
62
|
+
setTimeout(yellow, 6000);
|
63
|
+
function yellow() {
|
3
|
-
|
64
|
+
$('#yellow').css('background-color', 'yellow');
|
65
|
+
}
|
66
|
+
});
|
67
|
+
</script>
|
68
|
+
</body>
|
69
|
+
</html>
|
70
|
+
```
|