How to change the color of a div by timer via rgb?

  • 0
    There is a div, 300x200px in size, initially with a blue background (rgb (0,0,255)). Start a timer that decreases blue and increases red so that after about 10 seconds the div turns red, then stop the timer.
    JavaScript Eliot Solis, Feb 5, 2020

  • 3 Answers
  • 0
    rgb (0,0,255) - here division into Red Green Blue. That is, you need to consistently decrease Blue to 0, and increase Red to 255.



    You can call the function setInterval and change the values ​​at regular intervals. or constant
    Anonymous

  • 0
    https://jsfiddle.net/f2ca451m/ on the knee looks like this
    Anonymous

  • 0
    OMG

    Why do you need JS for this?

    On the knee option 1 option 2
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!