I am making something where the background is changing slowly but the colors change to fast so I was wondering if there was a sleep command of web js
Asked
Active
Viewed 75 times
-1
-
This is an [XY Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Mathletics Mar 28 '16 at 20:42
3 Answers
0
You can use setInterval if you want to change it:
var colors = ['red', 'green', 'blue']
var count = 0;
setInterval(function () {
document.body.style.backgroundColor = colors[count];
count ++ ;
if(count >= colors.length){
count = 0;
}
},1000)
kemiller2002
- 110,913
- 27
- 192
- 245
0
If you are trying to do an animation or transition for just a background read about transitions in css and make it with css for performance and simplicity sake.
Aleksandrenko
- 2,719
- 6
- 25
- 33
0
CSS animations are a good way to go.
@keyframes example {
from {background-color: red;}
to {background-color: purple;}
}
div {
width: 100px;
height: 100px;
background-color: red;
/* Reference her here */
animation-name: example;
animation-duration: 4s;
}