您好,登錄后才能下訂單哦!
本文實(shí)例為大家分享了swiper Scrollbar滾動(dòng)條組件的具體代碼,供大家參考,具體內(nèi)容如下
1、scrollbar
為Swiper增加滾動(dòng)條。類(lèi)型:object。
2、el
scrollbar容器的css選擇器或HTML元素。類(lèi)型:string/HTML Element,默認(rèn):.swiper-scrollbar。
3、hide
滾動(dòng)條是否自動(dòng)隱藏。類(lèi)型:boolean,默認(rèn):true(會(huì)自動(dòng)隱藏),false(不會(huì)自動(dòng)隱藏)。
4、draggable
設(shè)置為true時(shí)允許拖動(dòng)滾動(dòng)條。類(lèi)型:boolean,默認(rèn):false。
5、snapOnRelease
設(shè)置為false,釋放滾動(dòng)條時(shí)slide不會(huì)自動(dòng)切合。類(lèi)型:boolean,默認(rèn):true。
6、dragSize
設(shè)置滾動(dòng)條指示尺寸。默認(rèn):auto自動(dòng),或者設(shè)置為num(px)。類(lèi)型:string/number。
<script> var mySwiper = new Swiper('.swiper-container',{ scrollbar: { el: '.swiper-scrollbar', hide: true, draggable: false, snapOnRelease: true, dragSize: 20, } }) </script>
7、mySwiper.scrollbar.el
獲取滾動(dòng)條的HTML元素,還可以通過(guò)$el獲取DOM7。
8、mySwiper.scrollbar.dragEl
獲取滾動(dòng)條指示條的HTML元素,還可通過(guò)$dragEl獲取DOM7。
9、mySwiper.scrollbar.updateSize()
更新滾動(dòng)條。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>swiper-scrollbar滾動(dòng)條組件</title> <link rel="stylesheet" href="css/swiper.min.css" > <style> .swiper-container{ width: 500px; height: 214px; margin-bottom: 10px; } .swiper-slide{ text-align: center; line-height: 214px; font-size: 80px; color: #fff; } </style> </head> <body> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide" >slide1</div> <div class="swiper-slide" >slide2</div> <div class="swiper-slide" >slide3</div> </div> <div class="swiper-scrollbar"></div> </div> <script src="js/swiper.min.js"></script> <script> var mySwiper = new Swiper('.swiper-container',{ scrollbar: { el: '.swiper-scrollbar', hide: true, draggable: false, snapOnRelease: true, dragSize: 20, } }) mySwiper.scrollbar.$el.css('height','6px'); mySwiper.scrollbar.$dragEl.css('background','#fff'); mySwiper.scrollbar.updateSize(); </script> </body> </html>
注:swiper.min.css,swiper.min.js文件直接上Swiper官網(wǎng)下載。
參考Swiper API文檔
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。