<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="font/iconfont.css">
<link rel="stylesheet" href="new_file.css">
</head>
<body>
<div class="slideshow">
<img src="img/1.gif" class="current">
<img src="img/2.gif" class="next">
<img src="img/3.gif" >
<img src="img/4.gif" class="prev">
<div class="button left">
<span class="iconfont icon-xiangzuo"></span>
</div>
<div class="button right">
<span class="iconfont icon-xiangyou"></span>
</div>
</div>
<script src="new_file.js"></script>
</body>
</html>
*{
margin: 0;
padding: 0;
}
body{
height: 100vh;
background-color: rgb(170, 190, 250);
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.slideshow{
position: relative;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
img{
display: block;
width: 240px;
height: 320px;
background-color: white;
clip-path: circle(120px);
position: absolute;
opacity: 0;
z-index: -1;
transition: all 0.5s;
}
.current{
opacity: 1;
z-index: 99;
transform: scale(1.5);
}
.prev{
opacity: 0.5;
z-index: 10;
transform: translateX(-100%);
}
.next{
opacity: 0.5;
z-index: 10;
transform: translateX(100%);
}
.button{
position: absolute;
z-index: 100;
cursor: pointer;
background-color: black;
color: white;
width: 50px;
height: 50px;
border-radius: 50%;
text-align: center;
line-height: 50px;
opacity: 0.5;
}
.button span{
font-size: 25px;
}
.button.left{
transform: translateX(-180px);
}
.button.right{
transform: translateX(180px);
}
let left = document.querySelector('.left')
let right = document.querySelector('.right')
let imgs = document.querySelectorAll('img')
let prev = 3
let current = 0
let next = 1
console.log(prev,current,next);
left.onclick = ()=>{
prev = current
current = next
next = next + 1
if (next>3){
next=0
}
console.log(prev,current,next);
imgs.forEach((img)=>{img.removeAttribute('class')})
imgs[prev].className='prev'
imgs[current].className='current'
imgs[next].className='next'
}
right.onclick = ()=>{
next = current
current = prev
prev = prev - 1
if (prev<0){
prev=3
}
console.log(prev,current,next);
imgs.forEach((img)=>{img.removeAttribute('class')})
imgs[prev].className='prev'
imgs[current].className='current'
imgs[next].className='next'
}
标签:className,轮播,next,current,let,imgs,prev
From: https://www.cnblogs.com/duan-rui/p/17297159.html