基本信息
源码名称:文本自动切换背景颜色
源码大小:0.72KB
文件格式:.zip
开发语言:js
更新时间:2020-10-04
   源码介绍


<!DOCTYPE html>
<html>
<head>
<title>
</title>
<style>
    .a{
position: fixed;
top: 100px;
left: 100px;
    }
    .b{
        position: fixed;
top: 100px;
left: 200px;      
    }
    .c{
        position: fixed;
top: 100px;
left: 300px;  
    }
    .d{
        position: fixed;
top: 100px;
left: 400px;  
    }
    .e{
        position: fixed;
top: 100px;
left: 500px;   
    }
</style>
</head>
<body>
    <div class="a">德</div>
    <div class="b">智</div>
    <div class="c">体</div>
    <div class="d">美</div>
    <div class="e">劳</div>
    <script>
        var a=document.querySelector(".a");
        var b=document.querySelector(".b");
        var c=document.querySelector(".c");
        var d=document.querySelector(".d");
        var e=document.querySelector(".e");
var index=-1;
function change(){
    index  ;
    if(index==0){
        a.style.background="#00FF00";
        b.style.background="white";
        c.style.background="white";
        d.style.background="white";
        e.style.background="white";
    }
    if(index==1){
        a.style.background="white";
        b.style.background="#00FF00";
        c.style.background="white";
        d.style.background="white";
        e.style.background="white";
    }
    if(index==2){
        a.style.background="white";
        b.style.background="white";
        c.style.background="#00FF00";
        d.style.background="white";
        e.style.background="white";
    }
    if(index==3){
        a.style.background="white";
        b.style.background="white";
        c.style.background="white";
        d.style.background="#00FF00";
        e.style.background="white";
    }
    if(index==4){
        a.style.background="white";
        b.style.background="white";
        c.style.background="white";
        d.style.background="white";
        e.style.background="#00FF00";
    }
    if(index==5){
        index=-1;
    }
}
setInterval(change,1000);
    </script>
</body>
</html>