Skip to content Skip to sidebar Skip to footer

How To Change Background Color "continuously" Without Refreshing The Page

Is here any way to continuously change the background color like a rainbow?

Solution 1:

Hope you needed something like this.

var body = $('body');
var colors = ['red', 'green', 'blue', 'yellow', 'pink', 'purple'];
var currentIndex = 0;
setInterval(function () {
   body.css({
     backgroundColor: colors[currentIndex]
   });
   if (!colors[currentIndex]) {
       currentIndex = 0;
   } else {
       currentIndex++;
   }
}, 100);
body {
  transition: 200ms ease;
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Solution 2:

I hope you mean a rainbow effect? This CSS code can provide it:

.wrapper { 
  height: 100%;
  width: 100%;
  left:0;
  right: 0;
  top: 0;
  bottom: 0;
  position: absolute;
background: linear-gradient(124deg, #ff2400, #e81d1d, #e8b71d, #e3e81d, #1de840, #1ddde8, #2b1de8, #dd00f3, #dd00f3);
background-size: 1800%1800%;

-webkit-animation: rainbow 18s ease infinite;
-z-animation: rainbow 18s ease infinite;
-o-animation: rainbow 18s ease infinite;
  animation: rainbow 18s ease infinite;}

@-webkit-keyframes rainbow {
    0%{background-position:0%82%}
    50%{background-position:100%19%}
    100%{background-position:0%82%}
}
@-moz-keyframes rainbow {
    0%{background-position:0%82%}
    50%{background-position:100%19%}
    100%{background-position:0%82%}
}
@-o-keyframes rainbow {
    0%{background-position:0%82%}
    50%{background-position:100%19%}
    100%{background-position:0%82%}
}
@keyframes rainbow { 
    0%{background-position:0%82%}
    50%{background-position:100%19%}
    100%{background-position:0%82%}
}

Source: https://codepen.io/nohoid/pen/kIfto

Post a Comment for "How To Change Background Color "continuously" Without Refreshing The Page"