<!DOCTYPE html>
<html lang="en">
<head>css
<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="./dist/css/swiper.css">
</head>
<body>html
<div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide"> <img src="./banner1.png" alt=""> </div> <div class="swiper-slide"> <img src="./banner1.png" alt=""> </div> <div class="swiper-slide"> <img src="./banner1.png" alt=""> </div> </div> <!-- 若是須要分頁器(下面的小點點) --> <div class="swiper-pagination"></div> <!-- 若是須要導航按鈕 (左右按鈕)--> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> </div>
</body>
<script src="./jquery-2.0.0.min.js"></script>
<script src="./dist/js/swiper.js"></script>
<script>jquery
var mySwiper = new Swiper('.swiper-container', { direction: 'horizontal', //輪播方向 autoplay: true, //自動輪播 loop:true, //無限循環 speed: 800, // 若是須要分頁器 pagination: { el: '.swiper-pagination', }, // 若是須要前進後退按鈕 navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, // 若是須要滾動條 scrollbar: { el: '.swiper-scrollbar', }, autoplayDisableOnInteraction: false, observer: true, //修改swiper本身或子元素時,自動初始化swiper observeParents: true, //修改swiper的父元素時,自動初始化swiper })
</script>app
</html>ide
只須要在最外層的容器上增長class="swiper-no-swiping"oop