回答編集履歴
1
addEventListener -> stop を追加
answer
CHANGED
@@ -63,13 +63,13 @@
|
|
63
63
|
<!DOCTYPE html>
|
64
64
|
<title>sample</title>
|
65
65
|
<input type="button" value="開始" style="position:absolute;left:50px;top:20px" />
|
66
|
-
<input type="button" value="停止"
|
66
|
+
<input type="button" value="停止" style="position:absolute;left:90px;top:20px" />
|
67
67
|
<img id="myimg" src="number.gif" style="position:absolute;left:50px;top:50px;clip:rect(0px,60px,60px,0px)" />
|
68
68
|
<script>
|
69
69
|
'use strict';
|
70
70
|
var cy=0,y=50,TimeId;
|
71
71
|
|
72
|
-
function stop()
|
72
|
+
function stop(event)
|
73
73
|
{
|
74
74
|
clearInterval(TimeId);
|
75
75
|
var obj=document.getElementById("myimg");
|
@@ -94,9 +94,12 @@
|
|
94
94
|
}
|
95
95
|
|
96
96
|
document.querySelector('input[type=button][value="開始"]').addEventListener('click', function (event){
|
97
|
-
setInterval(scroll, 100);
|
97
|
+
TimeId = setInterval(scroll, 100);
|
98
98
|
}, false);
|
99
|
+
|
100
|
+
document.querySelector('input[type=button][value="停止"]').addEventListener('click', stop, false);
|
99
101
|
</script>
|
102
|
+
|
100
103
|
```
|
101
104
|
|
102
105
|
Re: hamutail さん
|