直接上代码,望君清楚
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>轮播图效果</title> <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"> <!-- Link Swiper's CSS --> <link rel="stylesheet" href="swiper.min.css"> <!-- Demo styles --> <style> html, body { position: relative; height: 100%; } body { background: #eee; font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 14px; color: #000; margin: 0; padding: 0; } .swiper-container { width: 500px; height: 300px; margin-top: 50px; } .swiper-slide { text-align: center; font-size: 18px; background: #fff; /* Center slide text vertically */ display: -webkit-box; display: -ms-flexbox; display: -webkit-flex; 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; } </style> </head> <body> <!-- Swiper --> <div> <div> <div>Slide 1</div> <div>Slide 2</div> <div>Slide 3</div> <div>Slide 4</div> <div>Slide 5</div> <div>Slide 6</div> <div>Slide 7</div> <div>Slide 8</div> <div>Slide 9</div> <div>Slide 10</div> </div> <!-- Add Pagination --> <div></div> <!-- Add Arrows --> <div></div> <div></div> </div> <!-- Swiper JS --> <script src="swiper.min.js"></script> <!-- Initialize Swiper --> <script> // 可以参考 180嵌套 、190抓手光标 、 200无限循环 、 2403D滚动切换 、 310缩略图/无限循环 // 缩放400 、 虚拟410 、自定义插件420 var swiper = new Swiper('.swiper-container', { spaceBetween: 30, //slide之间的距离 centeredSlides: true, //若为真,那么活动块会居中,而非默认状态下的居左 effect: 'cube', //翻转效果 zoom: true, //缩放图片比例 mousewheel: true, //鼠标滚动可以控制slide替换 autoplay: { //自动切换 delay: 2500, disableOnInteraction: false, }, pagination: { el: '.swiper-pagination', clickable: true, }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, }); </script> </body> </html>