微信小程序scroll-view仿拼多多橫向滑動(dòng)滾動(dòng)條
本文實(shí)例為大家分享了微信小程序橫向滑動(dòng)滾動(dòng)條的具體代碼,供大家參考,具體內(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 >
<!--滾動(dòng)條部分-->
<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:'',//分類類型,是否包含二級(jí)分類
slideWidth:'',//滑塊寬
slideLeft:0 ,//滑塊位置
totalLength:'',//當(dāng)前滾動(dòng)列表總長(zhǎ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
})
//計(jì)算比例
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; //分類列表總長(zhǎng)度
var _ratio = 230 / _totalLength * (750 / this.data.windowWidth); //滾動(dòng)列表長(zhǎng)度與滑條長(zhǎng)度比例
var _showLength = 750 / _totalLength * 230; //當(dāng)前顯示紅色滑條的長(zhǎng)度(保留兩位小數(shù))
this.setData({
slideWidth: _showLength,
totalLength: _totalLength,
slideShow: true,
slideRatio:_ratio
})
}
} ,
//slideLeft動(dòng)態(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)目地址:微信小程序橫向滑動(dòng)滾動(dòng)條
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)橫向滾動(dòng)條
- 微信小程序?qū)崿F(xiàn)滾動(dòng)條功能
- 微信小程序scroll-view隱藏滾動(dòng)條的方法詳解
- 微信小程序scroll-view的滾動(dòng)條設(shè)置實(shí)現(xiàn)
- 微信小程序設(shè)置滾動(dòng)條過程詳解
- 詳解微信小程序scroll-view橫向滾動(dòng)的實(shí)踐踩坑及隱藏其滾動(dòng)條的實(shí)現(xiàn)
- 微信小程序?qū)崿F(xiàn)swiper切換卡內(nèi)嵌滾動(dòng)條不顯示的方法示例
- 微信小程序-橫向滑動(dòng)scroll-view隱藏滾動(dòng)條
- 微信小程序 scroll-view隱藏滾動(dòng)條詳解
- 微信小程序scroll-view實(shí)現(xiàn)自定義滾動(dòng)條
相關(guān)文章
原生Javascript/原生JS修改CSS樣式的4種方式簡(jiǎn)單示例
在網(wǎng)頁(yè)開發(fā)中我們經(jīng)常會(huì)用到JavaScript來操作網(wǎng)頁(yè)元素,其中一個(gè)常見的操作就是修改元素的CSS樣式,下面這篇文章主要給大家介紹了關(guān)于原生Javascript/原生JS修改CSS樣式的4種方式,需要的朋友可以參考下2024-03-03
Javascript設(shè)計(jì)模式理論與編程實(shí)戰(zhàn)之簡(jiǎn)單工廠模式
簡(jiǎn)單工廠模式是由一個(gè)方法來決定到底要?jiǎng)?chuàng)建哪個(gè)類的實(shí)例, 而這些實(shí)例經(jīng)常都擁有相同的接口. 這種模式主要用在所實(shí)例化的類型在編譯期并不能確定, 而是在執(zhí)行期決定的情況。 說的通俗點(diǎn),就像公司茶水間的飲料機(jī),要咖啡還是牛奶取決于你按哪個(gè)按鈕2015-11-11
JS實(shí)現(xiàn)多張圖片預(yù)覽同步上傳功能
這篇文章主要介紹了JS實(shí)現(xiàn)多張圖片預(yù)覽同步上傳功能的相關(guān)資料,需要的朋友可以參考下2017-06-06
微信小程序?qū)崿F(xiàn)星級(jí)評(píng)分與展示
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)星級(jí)評(píng)分與展示,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
BootstrapTable請(qǐng)求數(shù)據(jù)時(shí)設(shè)置超時(shí)(timeout)的方法
使用bootstrapTable獲取數(shù)據(jù)時(shí),有時(shí)由于網(wǎng)絡(luò)或者服務(wù)器的原因,無法及時(shí)獲取到數(shù)據(jù),頁(yè)面顯示一直處于等待狀態(tài)。為了改善效果,考慮設(shè)置超時(shí),請(qǐng)求發(fā)送后超時(shí)即顯示無數(shù)據(jù),過段時(shí)間重新發(fā)起請(qǐng)求2017-01-01
layui實(shí)現(xiàn)數(shù)據(jù)表格隱藏列的示例
今天小編就為大家分享一篇layui實(shí)現(xiàn)數(shù)據(jù)表格隱藏列的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10

