首页 > 代码库 > js简单跑马灯案例

js简单跑马灯案例

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>跑马灯</title>    <style type="text/css">        *{            margin: 0;            padding: 0;        }        #bian{            width: 300px;            height: 300px;            margin:0 auto;        }        .deng{            width: 30px;            height: 30px;            float: left;            position: relative;            top: 49%;            left: 20%;            border-radius:50px;        }    </style></head><body>    <div id="bian">        <div class="deng" name="deng"></div>        <div class="deng" name="deng"></div>        <div class="deng" name="deng"></div>        <div class="deng" name="deng"></div>        <div class="deng" name="deng"></div>        <div class="deng" name="deng"></div>    </div></body><script type="text/javascript">    //获取所有元素    deng=document.getElementsByName(‘deng‘);    bian=document.getElementById(‘bian‘);    //设置颜色数组    list=["red","blue","green","yellow","orange","purple"];    //循环给div赋上颜色    for (var i = 0; i < deng.length; i++) {        deng[i].style.backgroundColor=list[i];            }    //定时器    setInterval(function(){            //把第一个节点插入当前节点的上一个节点之前            bian.insertBefore(deng[0],deng[0].previousSibling);    },10);    </script></html>

 

js简单跑马灯案例