在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Swiper是纯javascript打造的滑动特效插件,面向手机、平板电脑等移动终端。能实现触屏焦点图、触屏Tab切换、触屏多图切换等常用效果。超好用 1、首先加载插件,需要用到的文件有swiper.min.js和swiper.min.css文件。可下载Swiper文件或使用CDN。 <!-- Link Swiper--> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.2/css/swiper.min.css" rel="external nofollow" > <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.2/js/swiper.min.js"></script> 请勿直接引入Swiper中文网的文件 x <script src="http://www.swiper.com.cn/dist/js/swiper.min.js"></script> x <link href="http://www.swiper.com.cn/dist/css/swiper.min.css" rel="external nofollow" /> 2、CSS样式 <style> .swiper-container { //你可以在这里设置宽高 width: 50%; height: 50%; } .swiper-slide { text-align: center; font-size: 18px; background: #fff; /* Center slide text vertically */ display: flex; -webkit-box-pack: center; -ms-flex-pack: center; -webkit-justify-content: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; -webkit-align-items: center; align-items: center; } img{ width:250px; } </style> 3、HTML <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide"><img src="img/000.jpg" alt=""></div> <div class="swiper-slide"><img src="img/001.jpg" alt=""></div> <div class="swiper-slide"><img src="img/002.jpg" alt=""></div> <div class="swiper-slide"><img src="img/003.jpg" alt=""></div> <div class="swiper-slide"><img src="img/004.jpg" alt=""></div> //添加图片 </div> <!-- Add Pagination --> <div class="swiper-pagination"></div> <!-- Add Arrows --> <div class="swiper-button-next"></div> <div class="swiper-button-prev"></div> </div> 4、javaScript <script> var swiper = new Swiper('.swiper-container', { spaceBetween: 30, centeredSlides: true, autoplay: { delay: 2500, disableOnInteraction: false, }, pagination: { el: '.swiper-pagination', clickable: true, }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, }); </script> 效果图 你只需要替换一下图片,和修改一下图片及轮播图的大小就可以轻轻松松写出一个很棒的轮播图,怎么样是不是很简单 补充:怎么用swiper实现匀速无缝轮播
|
请发表评论