可以根据https://www.swiper.com.cn中的中文教材/swiper4.x使用方法课件做
先导入两个链接

  1. <link href="https://cdn.bootcss.com/Swiper/4.5.0/css/swiper.css" rel="stylesheet">
  2. <script src="https://cdn.bootcss.com/Swiper/4.4.6/js/swiper.js"></script>

实现轮播

  1. <link href="https://cdn.bootcss.com/Swiper/4.5.0/css/swiper.css" rel="stylesheet">
  2. <style>
  3. .swiper-container {
  4. width: 600px;
  5. height: 300px;
  6. }
  7. </style>
  8. </head>
  9. <body>
  10. <div class="swiper-container">
  11. <div class="swiper-wrapper">
  12. <div class="swiper-slide">Slide 1</div>
  13. <div class="swiper-slide">Slide 2</div>
  14. <div class="swiper-slide">Slide 3</div>
  15. </div>
  16. <!-- 如果需要分页器 -->
  17. <div class="swiper-pagination"></div>
  18. <!-- 如果需要导航按钮 -->
  19. <div class="swiper-button-prev"></div>
  20. <div class="swiper-button-next"></div>
  21. <!-- 如果需要滚动条 -->
  22. <div class="swiper-scrollbar"></div>
  23. </div>
  24. <script src="https://cdn.bootcss.com/Swiper/4.4.6/js/swiper.js"></script>
  25. <script>
  26. var mySwiper = new Swiper ('.swiper-container', {
  27. direction: 'horizontal', // 垂直切换选项
  28. loop: true, // 循环模式选项
  29. // 如果需要分页器
  30. pagination: {
  31. el: '.swiper-pagination',
  32. clickable:true
  33. },
  34. // 如果需要前进后退按钮
  35. navigation: {
  36. nextEl: '.swiper-button-next',
  37. prevEl: '.swiper-button-prev',
  38. },
  39. //自动播放
  40. autoplay: {
  41. delay: 2000,
  42. stopOnLastSlide: false,
  43. disableOnInteraction: false,
  44. }
  45. })
  46. </script>