所属分类:焦点图/幻灯片
导入swiper js和css
1 2 | < link rel = "stylesheet" type = "text/css" href = "./css/swiper.css" /> < script src = "./js/swiper.js" type = "text/javascript" charset = "utf-8" ></ script > |
以第一个轮播为列:
水平切换
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | < div class = "swiper-container" id = "case1" > < div class = "swiper-wrapper" > < div class = "swiper-slide" >< img src = "img/t1.png" ></ div > < div class = "swiper-slide" >< img src = "img/t2.png" ></ div > < div class = "swiper-slide" >< img src = "img/t4.png" ></ div > </ div > <!-- 导航按钮 上一页下一页 --> < div class = "swiper-button-prev" ></ div > < div class = "swiper-button-next" ></ div > <!-- 分页器 --> < div class = "swiper-pagination" ></ div > <!-- 滚动条 --> < div class = "swiper-scrollbar" ></ div > </ div > |
js内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | var mySwiper = new Swiper( '#case1' , { autoplay: true , //可选选项,自动滑动 initialSlide: 1, //默认显示第二张图片索引从0开始 speed: 2000, //设置过度时间 /* grabCursor: true,//鼠标样式根据浏览器不同而定 */ autoplay: { delay: 3000 }, /* 设置每隔3000毫秒切换 */ <!-- 分页器 --> pagination: { el: '.swiper-pagination' , clickable: true , }, <!-- 导航按钮 上一页下一页 --> navigation: { nextEl: '.swiper-button-next' , prevEl: '.swiper-button-prev' , }, <!-- 滚动条 --> scrollbar: { el: '.swiper-scrollbar' , hide: true , }, /* 设置当鼠标移入图片时是否停止轮播*/ autoplay: { disableOnInteraction: false , }, }); |
css内容:设置了一下宽高,居中显示
1 2 3 4 5 6 7 8 9 | p{ text-align : center ;} img{ width : 43.75 rem; height : 18.125 rem; } .swiper-container{ width : 43.75 rem; height : 18.125 rem; margin : 0 auto ; } |