swiper轮播的引入和使用
程序员文章站
2022-07-10 21:21:37
...
1、引入swiper的JS和css文件、去官网直接下载或者复制链接地址。
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.css">
<script src="https://unpkg.com/swiper/swiper-bundle.js"> </script>
2、复制基本的HTML代码块
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src="https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1830914723,3154965800&fm=26&gp=0.jpg"
alt=""></div>
<div class="swiper-slide">
<img src="https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1705581946,4177791147&fm=26&gp=0.jpg"
alt="">
</div>
<div class="swiper-slide">
<img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3202350968,2388474311&fm=26&gp=0.jpg"
alt="">
</div>
</div>
<!-- 如果需要分页器 -->
<div class="swiper-pagination"></div>
<!-- 如果需要导航按钮 -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- 如果需要滚动条 -->
<div class="swiper-scrollbar"></div>
</div>
3、复制JS
<script>
var mySwiper = new Swiper('.swiper-container', {
// direction: 'vertical', // 垂直切换选项
loop: true, // 循环模式选项
// 如果需要分页器
pagination: {
el: '.swiper-pagination',
clickable:true
},
// 如果需要前进后退按钮
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// 如果需要滚动条
scrollbar: {
el: '.swiper-scrollbar',
},
//设置自动轮播
autoplay:true
})
</script>
设置轮播swiper-container的宽高
.swiper-container{
width: 500px;
height: 300px;
}
再根据文档更改样式…
上一篇: Swiper插件的简单使用