2024-11-23 16:01:39
跑马灯效果吗
<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>
希望可以帮到你