js如何用定时器实现逐步给多个div加背景颜色并一直循环给颜色 5

 我来答
babyfans隆哥
2019-05-05 · TA获得超过112个赞
知道小有建树答主
回答量:205
采纳率:77%
帮助的人:63.6万
展开全部

跑马灯效果吗

<html>
<head>
<title>简单循环变色</title>
<style>
#a>div{
width:100px;
height:100px;
float:left;
}
</style>
</head>
<body>
<div id="a">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<script>
    function $(id){
        return (document.getElementById(id));
    }
var int = setInterval("clock()",500);
function clock(){
for (var i = 0; i < $('a').children.length-1; i++){
$('a').children[i].style["background-color"] = $('a').children[i+1].style["background-color"];
}
$('a').children[$('a').children.length-1].style["background-color"]='rgb(' + Math.floor(Math.random()*256) + ',' + Math.floor(Math.random()*256) + ',' + Math.floor(Math.random()*256) + ')';
}
</script>
</body>
</html>

希望可以帮到你

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式