<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>轮播图</title>
</head>
<style>
.banner{
width: 200px;
height: 150px;
margin: 100px auto;
position: relative;
}
.banner>div{
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
}
.one{
background: red;
}
.two{
background: green;
}
.three{
background: yellow;
}
</style>
<body>
<div class="banner">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
<script src="jquery.min.js"></script>
<script type="text/javascript">
$(".banner>div").eq(0).show().siblings().hide();
let len = $(".banner>div").length
let i = 0
setInterval(function(){
if(i<len - 1){
i++
}else{
i=0
}
$(".banner>div").eq(i).show().siblings().hide()
},2000)
</script>
</body>
</html>