🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
1.代码 ~~~ <!DOCTYPE html> <html lang="en"> <head> <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="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.5/css/swiper.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.5/js/swiper.js"></script> <script src="swiper/swiper.js"></script> <style> .swiper-container { width: 600px; height: 400px; } .swiper-pagination-bullet-active { background-color: #fff; } </style> </head> <body> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide"><img src="images/01.png" alt=""></div> <div class="swiper-slide"><img src="images/02.png" alt=""></div> <div class="swiper-slide"><img src="images/03.png" alt=""></div> </div> <!-- 如果需要分页器 --> <div class="swiper-pagination"></div> <!-- 如果需要导航按钮 --> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> </div> <script> </script> </body> </html> ~~~ 2. swiper.js ~~~ window.onload = function () { var mySwiper = new Swiper('.swiper-container', { // direction: 'horizonal', loop: true, autoplay: { delay: 2000, stopOnLastSlide: false, disableOnInteraction: false, }, // 如果需要分页器 pagination: { el: '.swiper-pagination', clickable:true }, // 如果需要前进后退按钮 navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, // 如果需要滚动条 scrollbar: { el: '.swiper-scrollbar', }, }) } ~~~ ### 修改 左右 使用iconfont ~~~ .swiper-button-prev,.swiper-button-next{ background: none; } .swiper-button-prev i,.swiper-button-next i{ font-size:40px; color: aqua; } <div class="swiper-button-prev"><i class="iconfont icon-left"></i></div> <div class="swiper-button-next"><i class="iconfont icon-zuoyoujiantou"></i></div> ~~~ 小圆点 ~~~ .swiper-pagination-bullet-active { opacity: 1; background: #6ce68a; } ~~~