152 lines
3.6 KiB
HTML
152 lines
3.6 KiB
HTML
<!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;
|
|
list-style: none;
|
|
}
|
|
|
|
.swiper-container {
|
|
width: 520px;
|
|
height: 280px;
|
|
margin: 10% auto;
|
|
position: relative;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.swiper-wrapper {
|
|
position: absolute;
|
|
display: flex;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.swiper-slide {
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.swiper-slide img {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.swiper-pagination {
|
|
display: flex;
|
|
position: absolute;
|
|
bottom: 15px;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
}
|
|
|
|
.pagination {
|
|
width: 15px;
|
|
height: 15px;
|
|
border-radius: 100%;
|
|
background: #fff;
|
|
margin-right: 10px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.pagination:last-child {
|
|
margin-right: 0;
|
|
}
|
|
|
|
.swiper-pagination .active {
|
|
background: red !important;
|
|
}
|
|
|
|
.swiper-button-prev,
|
|
.swiper-button-next {
|
|
width: 45px;
|
|
height: 45px;
|
|
background: rgb(0 0 0 / 58%);
|
|
color: #fff;
|
|
text-align: center;
|
|
line-height: 45px;
|
|
font-size: 18px;
|
|
position: absolute;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
border-radius: 100%;
|
|
}
|
|
|
|
.swiper-button-prev {
|
|
left: 10px;
|
|
}
|
|
|
|
.swiper-button-next {
|
|
right: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="swiper-container">
|
|
|
|
<div class="swiper-wrapper" style="left: 0px;">
|
|
<div class="swiper-slide">
|
|
<img src="https://gtms01.alicdn.com/tps/i1/TB1r4h8JXXXXXXoXXXXvKyzTVXX-520-280.jpg" alt="">
|
|
</div>
|
|
<div class="swiper-slide">
|
|
<img src="https://gtms03.alicdn.com/tps/i3/TB1gXd1JXXXXXapXpXXvKyzTVXX-520-280.jpg" alt="">
|
|
</div>
|
|
<div class="swiper-slide">
|
|
<img src="https://img.alicdn.com/imgextra/i2/6000000004940/O1CN01GJOBZe1mMZHhWNN9e_!!6000000004940-0-octopus.jpg"
|
|
alt="">
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 如果需要分页器 -->
|
|
<div class="swiper-pagination"></div>
|
|
|
|
<!-- 如果需要导航按钮 -->
|
|
<div class="swiper-button-prev"><</div>
|
|
<div class="swiper-button-next">></div>
|
|
|
|
</div>
|
|
|
|
<button>2222</button>
|
|
|
|
</body>
|
|
<script src="./index.js"></script>
|
|
<script>
|
|
var mySwiper = new Swiper(".swiper-container", {
|
|
<<<<<<< HEAD
|
|
loop: true,
|
|
autoPlay: true,
|
|
=======
|
|
loop: false,
|
|
autoPlay: false,
|
|
>>>>>>> 7d44fc1c419dd78aa3574780122af75387181afb
|
|
initialSlide: 0,
|
|
autoTime: 3000,
|
|
navigation: {
|
|
nextEl: '.swiper-button-next',
|
|
prevEl: '.swiper-button-prev',
|
|
},
|
|
pagination: {
|
|
el: '.swiper-pagination',
|
|
},
|
|
// on: {
|
|
// slideChange: function (index) {
|
|
// console.log("===== 1", index);
|
|
// },
|
|
// },
|
|
})
|
|
|
|
mySwiper.on("slideChange", (index) => {
|
|
console.log("===== 2", index);
|
|
})
|
|
|
|
document.querySelector("button").onclick = function () {
|
|
mySwiper.slideTo(1)
|
|
}
|
|
</script>
|
|
|
|
</html> |