效果图

轮播图源码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
width: 500px;
height: 300px;
margin: 10px auto;
overflow: hidden;
position: relative;
}
.carousel {
width: 100%;
height: 100%;
display: flex;
transition: 0.5s;
}
.container .carousel img {
width: 500px;
height: 300px;
}
.indicator {
position: absolute;
bottom: 10px;
display: flex;
left: 5%;
}
.indicator span{
width: 20px;
height: 20px;
border: 2px solid #ccc;
border-radius: 50%;
margin: 0 3px;
}
.indicator .active{
background:white;
border-color: white;
}
.btn{
position: absolute;
display: flex;
bottom: 20px;
flex-direction: row;
align-items: end;
right: 10%; }
.btn button{
display: block;
width: 20px;
height: 20px;
border: 2px solid #ccc;
border-radius: 50%;
margin-right: 10px;
right: 5%;
}
</style>
</head>
<body>
<div class="container">
<div class="carousel">
<div class="item"><img src="./img/1.jpg" alt=""></div>
<div class="item"><img src="./img/2.jpg" alt=""></div>
<div class="item"><img src="./img/3.jpg" alt=""></div>
<div class="item"><img src="./img/4.jpg" alt=""></div>
</div>
<div class="indicator">
<span class="active"></span>
<span></span>
<span></span>
<span></span>
</div>
<div class="btn">
<button id="pre">
P
</button>
<button id="next">
N
</button>
</div>
</div>
</div>
<script>
let doms = {
carousel:document.querySelector('.carousel'),
indicators:document.querySelectorAll('.indicator span'),
btnR :document.getElementById('next'),
btnL : document.getElementById('pre')
}
let index = 0
function moveTo(index){
doms.carousel.style.transform = `translateX(-${index}00%)`
let active = document.querySelector('.indicator .active')
active.classList.remove('active')
doms.indicators[index].classList.add('active')
}
doms.indicators.forEach(function(item,i){
item.onclick = function(){
moveTo(i)
index=i
}
})
setInterval(function(){
index++
index%=4
moveTo(index)
},2000)
doms.btnR.addEventListener("click",function(){
index++
index%=4
moveTo(index)
})
doms.btnL.addEventListener("click",function(){
index--
if(index<0){
index = 3
}
moveTo(index)
})
</script>
</body>
</html>