轮播图
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
body {
background-color: #cccccc;
}
.container {
width: 500px;
height: 300px;
margin: 50px auto;
position: relative;
}
.wipper {
width: 300px;
}
.wipper li {
width: 500px;
height: 300px;
display: none;
}
.wipper li:first-of-type {
background-color: red;
}
.wipper li:nth-of-type(2) {
background-color: orange;
}
.wipper li:nth-of-type(3) {
background-color: yellow;
}
.wipper li:nth-of-type(4) {
background-color: green;
}
.wipper li:nth-of-type(5) {
background-color: cyan;
}
.wipper li:nth-of-type(6) {
background-color: blue;
}
.wipper li:nth-of-type(7) {
background-color: purple;
}
.wipper li:first-of-type {
display: block;
}
.round {
position: absolute;
bottom: 30px;
right: 50px;
width: 200px;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
.round li {
width: 10px;
height: 10px;
border-radius: 50%;
background-color: white;
margin: 0px 7px;
}
.round li.color {
background-color: black;
}
.arrowleft {
width: 15px;
height: 50px;
background-color: black;
position: absolute;
top: 125px;
left: -15px;
cursor: pointer;
}
.arrowright {
width: 15px;
height: 50px;
background-color: black;
position: absolute;
top: 125px;
right: -15px;
cursor: pointer;
}
</style>
<body>
<div class="container">
<ul class="wipper">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<ul class="round">
<li class="color"></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<div class="arrowleft">
</div>
<div class="arrowright">
</div>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(function () {
let i = 0
let timer;
function run() {
timer = setInterval(function () {
if (++i === 7) i = 0
$('.wipper li').eq(i).show().siblings().hide()
$('.round li').eq(i).addClass('color').siblings('.color').removeClass('color')
}, 2000)
}
run();
$('.arrowleft').click(function () {
clearInterval(timer)
if (--i < 0) i = 6
$('.wipper li').eq(i).show().siblings().hide()
$('.round li').eq(i).addClass('color').siblings('.color').removeClass('color')
run()
})
$('.arrowright').click(function () {
clearInterval(timer)
if (++i > 6) i = 0
$('.wipper li').eq(i).show().siblings().hide()
$('.round li').eq(i).addClass('color').siblings('.color').removeClass('color')
run()
})
$('.round li').click(function () {
clearInterval(timer)
i = $(this).index();
$('.wipper li').eq(i).show().siblings().hide()
$('.round li').eq(i).addClass('color').siblings('.color').removeClass('color')
run()
})
})
</script>
</body>