skip to Main Content

Basically, I was making a clicker game, and after a certain thing happens, the background should gradually turn from blue to orange.

I am not exactly sure how to gradually change it, also, all of the things that say that they change the entire background actually don’t.

2

Answers


  1. You should make a class for the background.

    In JS just do to entirely change the background:

        if (condition) {
        document.getElementbyId('theID').style.color = "orange"
    }
    

    or you can make it a function that gets called on from an HTML tag. And to make it gradually change I am not exactly sure but try making editing your class in CSS and make it an animation there are plenty of tutorials for it.

    Login or Signup to reply.
  2. Explanation is in the code

    // Replace `condition` with the condition that should change the background color
    if (condition) {
      let body = document.querySelector("body"); // Getting the body as an object from tag
      body.style.backgroundColor = "orange"; // Changing the background color to orange
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search