How to make an HTML/CSS/JS color changing background (like Kahoot.it has)
Asked Answered
C

5

5

How do I make a color changing/fading background using html and css and possibly javascript similar to waht https://kahoot.it has?

Correspond answered 12/4, 2017 at 14:7 Comment(1)
Have you tried something ? at least inspect the elements .... you will find is pretty easy ... (Keyframe animation)Mercurous
O
14

You should learn to inspect and obtain

@keyframes bgcolor {
    0% {
        background-color: #45a3e5
    }

    30% {
        background-color: #66bf39
    }

    60% {
        background-color: #eb670f
    }

    90% {
        background-color: #f35
    }

    100% {
        background-color: #864cbf
    }
}

body {
    -webkit-animation: bgcolor 20s infinite;
    animation: bgcolor 10s infinite;
    -webkit-animation-direction: alternate;
    animation-direction: alternate;
}
Overmatter answered 12/4, 2017 at 14:22 Comment(2)
Thanks, I tried inspect element but couldn't figure out which file is was in.Correspond
@Correspond note that this solution alternates the color order, which you may be fine with. For example, if the color order is red, yellow, blue the colors would be run in this sequence: red, yellow, blue, yellow, red. Where the default would do red, yellow, blue, red, yellow, blue.Deration
D
4

body {
  animation: 10000ms ease-in-out infinite color-change;
}

@keyframes color-change {
  0% {
    background-color: teal;
  }
  20% {
    background-color: gold;
  }
  40% {
    background-color: indianred;
  }
  60% {
    background-color: violet;
  }
  80% {
    background-color: green;
  }
  100% {
    background-color: teal;
  }
}
Deration answered 12/4, 2017 at 14:27 Comment(0)
C
1

You really didn't show us anything in terms of you trying. But I'm a nice guy and I know you will learn by example:

div {
  animation: colorchange 10s infinite; 
}

@keyframes colorchange {
  0%   {background-color: red;}
  25%  {background-color: yellow;}
  50%  {background-color: blue;}
  75%  {background-color: green;}
  100% {background-color: red;}
}

Modify as needed.

Cort answered 12/4, 2017 at 14:20 Comment(1)
Sorry, I could get stuff that worked, but didn't look right, I forgot to post it.Correspond
M
1
/* The animation code */
@keyframes example {
    0%   {background-color: red;}
    33%  {background-color: yellow;}
    66%  {background-color: blue;}
    100%   {background-color: red;}
}

/* The element to apply the animation to */
div {
    width: 100px;
    height: 100px;
    background-color: red;
    animation-name: example;
    animation-duration: 10s;
    animation-iteration-count: infinite;
}
Marikomaril answered 12/4, 2017 at 14:23 Comment(0)
R
0

Bruh just do this:

@keyframes bgcolor {
    0% {
        background-color: #45a3e5
    }

    30% {
        background-color: #66bf39
    }

    60% {
        background-color: #eb670f
    }

    90% {
        background-color: #f35
    }

    100% {
        background-color: #864cbf
    }
}

body {
    -webkit-animation: bgcolor 20s infinite;
    animation: bgcolor 10s infinite;
    -webkit-animation-direction: alternate;
    animation-direction: alternate;
}
Rhamnaceous answered 21/10, 2019 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.