怎样利用jquery控制swiper的页数

 我来答
西安天融信教育
2018-02-27 · TA获得超过996个赞
知道小有建树答主
回答量:1629
采纳率:73%
帮助的人:191万
展开全部
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>swiper自定义分页器用法</title> <link href="swiper-3.4.2.min.css" rel="stylesheet" /> <style> * { padding: 0; margin: 0; } .swiper-container { position: relative; width: 100%; height: 100%; } .swiper-slide { text-align: center; font-size: 18px; background: #fff; 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; } .swiper-slide img { display: block; width: 100%; max-width: 100%; } /*包裹自定义分页器的div的位置等CSS样式*/ .swiper-pagination-custom { bottom: 10px; left: 0; width: 100%; } /*自定义分页器的样式,这个你自己想要什么样子自己写*/ .swiper-pagination-customs { width: 30px; height: 4px; display: inline-block; background: #000; opacity: .3; margin: 0 5px; } /*自定义分页器激活时的样式表现*/ .swiper-pagination-customs-active { opacity: 1; background-color: #F78E00; } </style> </head> <body> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide"> <img src="banner1_.jpg" alt="轮播图1" /> </div> <div class="swiper-slide"> <img src="banner2_.jpg" alt="轮播图2" /> </div> </div> <div class="swiper-pagination"></div> </div> </body> <script src="jquery.min.js"></script> <script type="text/javascript" src="swiper.min.js"></script> <script> var mySwiper = new Swiper('.swiper-container', { direction: 'horizontal', loop: true, autoplay: 3000,//自动轮播 speed: 600, // 如果需要分页器 pagination: '.swiper-pagination', paginationType: 'custom',//这里分页器类型必须设置为custom,即采用用户自定义配置 //下面方法可以生成我们自定义的分页器到页面上 paginationCustomRender: function(swiper, current, total) { var customPaginationHtml = ""; for(var i = 0; i < total; i++) { //判断哪个分页器此刻应该被激活 if(i == (current - 1)) { customPaginationHtml += '<span class="swiper-pagination-customs swiper-pagination-customs-active"></span>'; } else { customPaginationHtml += '<span class="swiper-pagination-customs"></span>'; } } return customPaginationHtml; } }); </script> </html>
小巴菜鸟
2018-02-27 · TA获得超过908个赞
知道小有建树答主
回答量:2727
采纳率:63%
帮助的人:221万
展开全部
有轮播插件,代码更少,效果更好。去看swiper。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式