1.首先加载插件,需要用到的文件有swiper.min.js和swiper.min.css文件。
2.HTML内容。
<!DOCTYPE html>
<html>
<head><link rel="stylesheet" href="path/to/swiper.min.css">
</head>
<body>
<script src="path/to/jquery.js"></script>
<script src="path/to/swiper.jquery.min.js"></script>
//滑动轮播
<div class="swiper-container">
<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>
<!-- 如果需要分页器 -->
<div class="swiper-pagination"></div>
<!-- 如果需要导航按钮 -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- 如果需要滚动条 -->
<div class="swiper-scrollbar"></div>
</div>
导航等组件可以放在container之外
</body>
</html>
3.初始化Swiper:最好是挨着</body>标签
<script>var mySwiper = new Swiper ('.swiper-container', { direction: 'vertical', loop: true, // 如果需要分页器 pagination: '.swiper-pagination', // 如果需要前进后退按钮 nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', // 如果需要滚动条 scrollbar: '.swiper-scrollbar', // 3D效果滑动 effect: 'cube', grabCursor: true, cube: { shadow: true, slideShadows: true, shadowOffset: 20, shadowScale: 0.94 } // 中间有slide中间有间隙 paginationClickable: true, spaceBetween: 30, // slide分组显示 slidesPerView: 3, // 自动分组显示 slidesPerView: 'auto', // 多行分组显示 slidesPerView: 3, slidesPerColumn: 2, //嵌套滑动 var swiperH = new Swiper('.swiper-container-h', { pagination: '.swiper-pagination-h', paginationClickable: true, spaceBetween: 50 }); var swiperV = new Swiper('.swiper-container-v', { pagination: '.swiper-pagination-v', paginationClickable: true, direction: 'vertical', spaceBetween: 50 }); }) </script>