<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>咪咕音乐</title>
<style>
* {
margin: 0;
padding: 0;
}
body{
background-color: black;
}
#swiper {
position: relative;
}
.swiper {
width: 1400px;
height: 380px;
margin: 0 auto;
position: relative;
}
.swiperItem {
width: 1400px;
height: 350px;
position: absolute;
transition: .5s;
box-shadow: 0 0 15px #b0b0b0;
border-radius: 10px;
overflow: hidden;
}
.swiperItem > img {
width: 1400px;
height: 350px;
display: block;
}
.def {
opacity: 0;
z-index: -1;
transform:perspective(500px) translateZ(-250px);
}
.c {
opacity: 1;
z-index: 1;
transform: perspective(500px) translateZ(-230px) translateX(230px);
}
.a {
opacity: 1;
z-index: 1;
transform: perspective(500px) translateZ(-230px) translateX(-230px);
}
.b {
opacity: 1;
z-index: 999;
transform: perspective(500px) translateZ(-100px) translateX(0px);
}
.btn {
position: absolute;
width: 51px;
height: 100px;
top: 34%;
}
.btn_left {
left: 0;
background-image: url(./img/btn-left.png);
}
.btn_right {
right: 0;
background-image: url(./img/btn-right.png);
}
.btn_left:hover {
background-image: url(./img/btn-left-hover.png);
}
.btn_right:hover {
background-image: url(./img/btn-right-hover.png);
}
.ponts{
width: 200px;
height: 4px;
margin: 0 auto;
display:flex;
justify-content: space-around;
}
.ponts a{
width: 15px;
height: 4px;
background-color: #b0b0b0;
border-radius: 2px;
}
.ponts .show{
background-color: aqua;
}
.ponts .hidden{
background-color:#b0b0b0;
}
</style>
</head>
<body>
<div id="swiper">
<div class="swiper">
<div class="swiperItem b">
<a href="#">
<img src="./img/01.jpg" alt="" />
</a>
</div>
<div class="swiperItem c">
<a href="#">
<img src="./img/02.jpg" alt="" />
</a>
</div>
<div class="swiperItem def">
<a href="#">
<img src="./img/03.jpg" alt="" />
</a>
</div>
<div class="swiperItem def">
<a href="#">
<img src="./img/04.jpg" alt="" />
</a>
</div>
<div class="swiperItem def">
<a href="#">
<img src="./img/05.jpg" alt="" />
</a>
</div>
<div class="swiperItem def">
<a href="#">
<img src="./img/06.jpg" alt="" />
</a>
</div>
<div class="swiperItem a">
<a href="#">
<img src="./img/07.jpg" alt="" />
</a>
</div>
</div>
<a href="#" class="btn btn_left"></a>
<a href="#" class="btn btn_right"></a>
<div class="ponts">
<a href="#" class="show"></a>
<a href="#" class="hidden"></a>
<a href="#" class="hidden"></a>
<a href="#" class="hidden"></a>
<a href="#" class="hidden"></a>
<a href="#" class="hidden"></a>
<a href="#" class="hidden"></a>
</div>
</div>
<script src="./轮播图.js"></script>
</body>
</html>
let swiper = document.querySelector("#swiper");
let swiperItem = document.querySelectorAll(".swiperItem");
let points = document.querySelectorAll(".ponts a");
let btn_left = document.querySelector(".btn_left");
let btn_right = document.querySelector(".btn_right");
let nowIndex = 0;
let timer;
swiperPlay();
function swiperPlay() {
clearInterval(timer);
timer = setInterval(() => {
nowIndex++;
if (nowIndex === swiperItem.length) {
nowIndex = 0;
}
changeAll();
}, 2000);
}
function changeAll() {
changeImg();
changePoint();
}
function changeImg() {
for (let i = 0; i < swiperItem.length; i++) {
swiperItem[i].className = "swiperItem def";
if (nowIndex === 0) {
swiperItem[nowIndex].className = "swiperItem b";
swiperItem[swiperItem.length - 1].className = "swiperItem a";
swiperItem[nowIndex + 1].className = "swiperItem c";
} else if (nowIndex === swiperItem.length - 1) {
swiperItem[nowIndex].className = "swiperItem b";
swiperItem[nowIndex - 1].className = "swiperItem a";
swiperItem[0].className = "swiperItem c";
} else {
swiperItem[nowIndex].className = "swiperItem b";
swiperItem[nowIndex - 1].className = "swiperItem a";
swiperItem[nowIndex + 1].className = "swiperItem c";
}
}
}
function changePoint() {
for (let m = 0; m < points.length; m++) {
points[m].className = "hidden";
}
points[nowIndex].className = "show";
}
for (let n = 0; n < points.length; n++) {
points[n].index = n;
points[n].onclick = function () {
nowIndex = this.index;
changeAll();
};
}
for (let t = 0; t < swiperItem.length; t++) {
swiperItem[t].index = t;
swiperItem[t].onclick = function () {
nowIndex = this.index;
changeAll();
};
}
btn_left.onclick = function () {
nowIndex--;
if (nowIndex < 0) {
nowIndex = swiperItem.length - 1;
}
changeAll();
};
btn_right.onclick = function () {
nowIndex++;
if (nowIndex === swiperItem.length) {
nowIndex = 0;
}
changeAll();
};
swiper.onmouseover = function () {
clearInterval(timer);
};
swiper.onmouseout = function () {
swiperPlay();
};