-1

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

Kiuy
  • 1
  • 2

3 Answers3

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)

https://jsfiddle.net/kemiller2002/od5ho3f2/

kemiller2002
  • 113,795
  • 27
  • 197
  • 251
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.

https://www.google.bg/search?q=css+transition+change+background+image&oq=css+transition+change+background+image&aqs=chrome..69i57j0l2.261j0j1&sourceid=chrome&ie=UTF-8

Aleksandrenko
  • 2,987
  • 6
  • 28
  • 34
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;
}

http://www.w3schools.com/css/css3_animations.asp