国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 課堂 > 小程序 > 正文

微信小程序scroll-view仿拼多多橫向滑動滾動條

2020-03-21 16:14:26
字體:
來源:轉載
供稿:網友

本文實例為大家分享了微信小程序橫向滑動滾動條的具體代碼,供大家參考,具體內容如下

效果圖

微信小程序,scroll-view,仿拼多多,滾動條

微信小程序,scroll-view,仿拼多多,滾動條

實現代碼

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">    <!--內容區域-->    <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

//獲取應用實例var app = getApp();Page({ data: {  navigate_type:'',//分類類型,是否包含二級分類  slideWidth:'',//滑塊寬  slideLeft:0 ,//滑塊位置  totalLength:'',//當前滾動列表總長  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(); }, //根據分類獲取比例 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; //當前顯示紅色滑條的長度(保留兩位小數)   this.setData({    slideWidth: _showLength,    totalLength: _totalLength,    slideShow: true,    slideRatio:_ratio   })  } } , //slideLeft動態變化 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;}

項目地址:微信小程序橫向滑動滾動條

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 屏南县| 博爱县| 金乡县| 聊城市| 尼玛县| 双柏县| 望江县| 池州市| 郯城县| 泰来县| 大余县| 汕头市| 临邑县| 任丘市| 康马县| 金阳县| 麻江县| 通辽市| 宜章县| 乳源| 上栗县| 克什克腾旗| 岚皋县| 和静县| 天水市| 肃北| 广平县| 吉林市| 正宁县| 钟山县| 芜湖县| 新和县| 龙州县| 通州区| 长岭县| 乌拉特前旗| 余庆县| 怀集县| 丰原市| 铜鼓县| 扶绥县|