87,910
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
ul li{float:left;height:50px;width:50px;margin:0 6px;background:#ccc;list-style:none;}
ul .active{background:red;}
</style>
</head>
<body>
</body>
<div class="ob" id="ob" draggable="true">
<ul>
<li class="active">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
<script>
function $(select){
return document.querySelector(select);
}
function $$(select){
return document.querySelectorAll(select);
}
var li = $$("ul li");
var num = li.length;
var count = 1;
(function(time){
setInterval(function(){
if(count < num){
$("#ob .active").className = "";
li.item(count).className = "active";
count++;
}else{
count = 0;
$("#ob .active").className = "";
li.item(count).className = "active";
count++;
}
},time);
})(1000); //切换的时间
</script>
</body>
</html>