效果图-样式颜色很丑,需要的请自行优化
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Swiper demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
<!-- Link Swiper's CSS -->
<link rel="stylesheet" href="assets/styles/other/swiper-bundle.min.css" />
<!-- Demo styles -->
<style>
html,
body {
position: relative;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #000;
margin: 0;
padding: 0;
}
.swiper {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
display: flex;
justify-content: center;
align-items: center;
}
.swiper-slide img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
.swiper-slide::before{
content: '';
left: 0;
top: 0;
width: 100%;
height: 2px;
background-color: #000;
position: absolute;
transform: scaleX(0);
transform-origin: left;
z-index: 3;
transition-timing-function: linear;
}
.swiper-pagination-bullet{
background-color: transparent;
opacity: 1;
margin: 0 6px !important;
width: 60px;
height: 9px;
position: relative;
outline: none;
vertical-align: middle;
}
.swiper-pagination-bullet span{
width: 60px;
height: 3px;
background-color: #ccc;
display: block;
margin-top: 3px;
}
.swiper-pagination-bullet i{
background-color: #000;
height: 3px;
width: 60px;
position: absolute;
top: 4px;
transform: scaleX(0);
transform-origin: left;
z-index: 3;
transition-timing-function: linear;
}
.swiper-pagination-bullet-active i{
animation: middle 5s forwards;//与autoplay delay的时间保持一致
}
@keyframes middle{
0%{
transform: scaleX(0);
left: 0;
}
100%{
transform: scaleX(1);
left: 0;
}
}
</style>
</head>
<body>
<div class="swiper mySwiper">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
<div class="swiper-slide">Slide 4</div>
<div class="swiper-slide">Slide 5</div>
<div class="swiper-slide">Slide 6</div>
<div class="swiper-slide">Slide 7</div>
<div class="swiper-slide">Slide 8</div>
<div class="swiper-slide">Slide 9</div>
</div>
<div class="swiper-pagination"></div>
</div>
<!-- Swiper JS -->
<script src="assets/scripts/other/swiper-bundle.min.js"></script>
<!-- Initialize Swiper -->
<script>
var swiper = new Swiper(".mySwiper", {
autoplay: {
delay: 5000,
},
pagination: {
el: ".swiper-pagination",
clickable: true,
renderBullet: function (index, className) {
return '<div class="' + className + '"><span></span><i></i></div>';
},
},
});
</script>
</body>
</html>