微信小程序scroll-view仿拼多多橫向滑動滾動條
本文實(shí)例為大家分享了微信小程序橫向滑動滾動條的具體代碼,供大家參考,具體內(nèi)容如下
效果圖
實(shí)現(xiàn)代碼
index.wxml
<scroll-view scroll-x="true" class="scroll-view-x" style="padding-top:10rpx" scroll-with-animation="true" wx:if="{{tlist[currentTab].secondList}}" scroll-left='0' bindscroll="getleft"> <!--內(nèi)容區(qū)域--> <view> <view class="navigator_second" wx:for="{{tlist[currentTab].secondList}}" wx:for-item="childItem" bindtap="getProductList" data-id="{{childItem.id}}"> <image class="navigator_icon" src="{{childItem.icon}}"></image> <text class="navigator_text">{{childItem.name}}</text> </view> </view> <view wx:if="{{tlist[currentTab].thirdList}}"> <view class="navigator_second" wx:for="{{tlist[currentTab].thirdList}}" wx:for-item="childItem" data-id="{{childItem.id}}" bindtap="getProductList"> <image class="navigator_icon" src="{{childItem.icon}}" ></image> <text class="navigator_text">{{childItem.name}}</text> </view> </view> </scroll-view > <!--滾動條部分--> <view wx:if="{{slideShow}}" class="slide"> <view class='slide-bar' > <view class="slide-show" style="width:{{slideWidth}}rpx; margin-left:{{slideLeft<=1 ? 0 : slideLeft+'rpx'}};"></view> </view> </view>
index.js
//獲取應(yīng)用實(shí)例 var app = getApp(); Page({ data: { navigate_type:'',//分類類型,是否包含二級分類 slideWidth:'',//滑塊寬 slideLeft:0 ,//滑塊位置 totalLength:'',//當(dāng)前滾動列表總長 slideShow:false, slideRatio:'' }, onLoad: function () { var self = this ; var systemInfo = wx.getSystemInfoSync() ; self.setData({ list: _list, windowHeight: app.globalData.navigate_type == 1 ? systemInfo.windowHeight : systemInfo.windowHeight - 35, windowWidth: systemInfo.windowWidth, navigate_type: app.globalData.navigate_type }) //計算比例 self.getRatio(); }, //根據(jù)分類獲取比例 getRatio(){ var self = this ; if (!self.data.tlist[self.data.currentTab].secondList || self.data.tlist[self.data.currentTab].secondList.length<=5){ this.setData({ slideShow:false }) }else{ var _totalLength = self.data.tlist[self.data.currentTab].secondList.length * 150; //分類列表總長度 var _ratio = 230 / _totalLength * (750 / this.data.windowWidth); //滾動列表長度與滑條長度比例 var _showLength = 750 / _totalLength * 230; //當(dāng)前顯示紅色滑條的長度(保留兩位小數(shù)) this.setData({ slideWidth: _showLength, totalLength: _totalLength, slideShow: true, slideRatio:_ratio }) } } , //slideLeft動態(tài)變化 getleft(e){ this.setData({ slideLeft: e.detail.scrollLeft * this.data.slideRatio }) } })
index.wxss
.scroll-view-x{ background-color: #fff; white-space: nowrap; } .navigator_second{ width:150rpx; text-align:center; display:inline-block; height:115rpx; } .navigator_icon{ width:60rpx; height:60rpx; } .navigator_text{ display:block; width:100%; font-size:24rpx } .slide{ height:30rpx; background:#fff; with:100%; padding:14rpx 0 5rpx 0 } .slide .slide-bar{ width:230rpx; margin:0 auto; height:1.5px; background:#eee; } .slide .slide-bar .slide-show{ height:100%; background-color:#ff6969; }
項(xiàng)目地址:微信小程序橫向滑動滾動條
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)橫向滾動條
- 微信小程序?qū)崿F(xiàn)滾動條功能
- 微信小程序scroll-view隱藏滾動條的方法詳解
- 微信小程序scroll-view的滾動條設(shè)置實(shí)現(xiàn)
- 微信小程序設(shè)置滾動條過程詳解
- 詳解微信小程序scroll-view橫向滾動的實(shí)踐踩坑及隱藏其滾動條的實(shí)現(xiàn)
- 微信小程序?qū)崿F(xiàn)swiper切換卡內(nèi)嵌滾動條不顯示的方法示例
- 微信小程序-橫向滑動scroll-view隱藏滾動條
- 微信小程序 scroll-view隱藏滾動條詳解
- 微信小程序scroll-view實(shí)現(xiàn)自定義滾動條
相關(guān)文章
詳解webpack4多入口、多頁面項(xiàng)目構(gòu)建案例
這篇文章主要介紹了詳解webpack4多入口、多頁面項(xiàng)目構(gòu)建案例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05Javascript ES6中對象類型Sets的介紹與使用詳解
這篇文章主要給大家介紹了關(guān)于Javascript ES6中Sets的介紹與使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-07-07JavaScript防抖與節(jié)流的實(shí)現(xiàn)與注意事項(xiàng)
防抖和節(jié)流嚴(yán)格算起來應(yīng)該屬于性能優(yōu)化的知識,但實(shí)際上遇到的頻率相當(dāng)高,處理不當(dāng)或者放任不管就容易引起瀏覽器卡死,下面這篇文章主要給大家介紹了關(guān)于JavaScript防抖與節(jié)流的實(shí)現(xiàn)與注意事項(xiàng),需要的朋友可以參考下2022-03-03HTML+CSS+JS實(shí)現(xiàn)的簡單應(yīng)用小案例分享
這篇文章主要為大家分享四個用HTML+CSS+JS實(shí)現(xiàn)的簡單應(yīng)用小案例,有:猜數(shù)字、表白墻、切換日夜間模式和待辦事項(xiàng),需要的可以參考一下2022-02-02JS實(shí)現(xiàn)黑色大氣的二級導(dǎo)航菜單效果
這篇文章主要介紹了JS實(shí)現(xiàn)黑色大氣的二級導(dǎo)航菜單效果,具有延遲響應(yīng)鼠標(biāo)事件顯示切換效果的功能,非常簡單實(shí)用,需要的朋友可以參考下2015-09-09JavaScript基礎(chǔ)進(jìn)階之?dāng)?shù)組方法總結(jié)(推薦)
下面小編就為大家?guī)硪黄狫avaScript基礎(chǔ)進(jìn)階之?dāng)?shù)組方法總結(jié)(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09JS Array.from()將偽數(shù)組轉(zhuǎn)換成數(shù)組的方法示例
這篇文章主要介紹了JS Array.from()將偽數(shù)組轉(zhuǎn)換成數(shù)組的方法示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03