首先我们新建一个文件夹名为lunbotu1在它下面新建三个文件夹分别名为js css img 和index.html
如图所示
然后我们打开命令行输入以下代码
npm init -y 初始化命令
npm i swiper@4.0.1 下载4.0.1版本的swiper
如图所示
然后我们编写html代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> </style> </head> <!--Swiper5/Swiper4,要将5.x.x改成相应的版本,如5.4.5或4.5.1版本(4无esm的CDN)--> <!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/5.x.x/css/swiper.css">--> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.1/css/swiper.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.1/js/swiper.min.js"></script> <!--min--> <body> <div class="swiper"> <div class="swiper-wrapper"> <div class="swiper-slide"><img src="./img/01.jpg" alt=""></div> <div class="swiper-slide"><img src="./img/02.jpg" alt=""></div> <div class="swiper-slide"><img src="./img/03.jpg" alt=""></div> </div> </div> <script> var mySwiper = new Swiper('.swiper', { autoplay: true,//可选选项,自动滑动 }) </script> </body> </html> <!--<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/5.x.x/js/swiper.js"></script>--> <!--<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/5.x.x/js/swiper.esm.js"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.1/js/swiper.min.js"></script>
首先我们链入下载好的swiper.min.js
script代码如下
var mySwiper = new Swiper('.swiper', { autoplay: true,//可选选项,自动滑动 })
界面效果如下