Skip to content

Commit ce54f08

Browse files
committed
js-task1-2
1 parent cba5f97 commit ce54f08

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

js-task1/js.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
var boxs = document.getElementById('header').getElementsByTagName('div');
22
var colors = ['red','plum','blue','green','cyan','black','pink','gray','brown'];
3-
4-
function start(){
5-
t = setInterval(function(){
3+
var timer = null;
4+
function changes(){
65
for (var i = 0; i < boxs.length; i++) {
76
boxs[i].style.background = "#ffa600";
87
}
@@ -45,15 +44,21 @@ function start(){
4544
console.log(arr[i]);
4645
console.log(i);
4746
}
47+
}
4848

49+
50+
function start(){
51+
clearInterval(timer);
52+
timer = setInterval(function(){
53+
changes();
4954
},1000)
5055
}
5156

5257
function stop(){
5358
for (i = 0; i < boxs.length; i++) {
5459
boxs[i].style.background="#ffa600";
5560
}
56-
clearInterval(t);
61+
clearInterval(timer);
5762
}
5863

5964

0 commit comments

Comments
 (0)