How do I change the background color with JavaScript?

后端 未结 19 2653
春和景丽
春和景丽 2020-11-22 13:59

Anyone know a simple method to swap the background color of a webpage using JavaScript?

19条回答
  •  长情又很酷
    2020-11-22 14:41

    Css approach:

    If you want to see continuous colour, use this code:

    body{
        background-color:black;
        animation: image 10s infinite alternate;
        animation:image 10s infinite alternate;
        animation:image 10s infinite alternate;
    }
    
    @keyframes image{
        0%{
    background-color:blue;
    }
    25%/{
        background-color:red;
    }
    50%{
        background-color:green;
    }
    75%{
    
        background-color:pink;
    }
    100%{
        background-color:yellow;
        }
      }  
    

    If you want to see it faster or slower, change 10 second to 5 second etc.

提交回复
热议问题