发布作者: Miss
百度收录: 正在检测是否收录...
最后更新: 2023年 12月 27日 17:07
作品采用: 《 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 》许可协议授权
swiper轮播 无所不能 主要还可以用来实现置顶文章轮播😀 正好本站也用上了
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.5/css/swiper.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.5/js/swiper.js"></script>
<style>
.swiper-container {
width: 600px;
height: 400px;
}
.swiper-pagination-bullet-active {
background-color: #fff;
}
</style>
</head>
<body>
<div class="swiper-container"> <!-- 如果需要关闭手动控制滑动 把标签swiper-no-swiping添加进去-->
<div class="swiper-wrapper">
<!-- 这里放轮播的东西 图片文字都可以 -->
<div class="swiper-slide"><img src="images/01.png" alt=""></div>
<div class="swiper-slide"><img src="images/02.png" alt=""></div>
<div class="swiper-slide"><img src="images/03.png" alt=""></div>
</div>
<!-- 如果需要分页器 -->
<div class="swiper-pagination"></div>
<!-- 如果需要导航按钮 -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
<script>
window.onload = function () {
var mySwiper = new Swiper('.swiper-container', {
// direction: 'horizonal',
loop: true,
autoplay: {
delay: 2000, // 轮播间隔时间
stopOnLastSlide: false,
disableOnInteraction: false,
},
// 如果需要分页器
pagination: {
el: '.swiper-pagination',
clickable:true
},
// 如果需要前进后退按钮
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// 如果需要滚动条
scrollbar: {
el: '.swiper-scrollbar',
},
})
}
</script>
</body>
</html>
.swiper-button-prev,.swiper-button-next{
background: none;
}
.swiper-button-prev i,.swiper-button-next i{
font-size:40px;
color: aqua;
}
<div class="swiper-button-prev"><i class="iconfont icon-left"></i></div>
<div class="swiper-button-next"><i class="iconfont icon-zuoyoujiantou"></i></div>
.swiper-pagination-bullet-active {
opacity: 1;
background: #6ce68a;
}
—— 评论区 ——