微信小程序?qū)崿F(xiàn)橫向滾動(dòng)條
本文實(shí)例為大家分享了微信小程序橫向滾動(dòng)條的具體代碼,供大家參考,具體內(nèi)容如下
微信小程序scroll-view實(shí)現(xiàn)橫向滑動(dòng)滾動(dòng)
效果圖如下:
左右滑動(dòng)效果展示如下:
實(shí)現(xiàn)代碼:
index.wxml
<view class="hotService"> ?? ?<view class="hotServiceList_box"> ?? ?<!-- 這里為滾動(dòng)的內(nèi)容部分 --> ?? ??? ??? ?<scroll-view class="hotServiceList_scroll" scroll-x="true" bindscroll="getleft"> ?? ??? ??? ??? ?<view class="hotService_content"> ?? ??? ??? ??? ??? ?<block wx:for="{{dataList}}" wx:key="{{index}}"> ?? ??? ??? ??? ??? ??? ?<view class="block{{index}} block"> ?? ??? ??? ??? ??? ??? ??? ?<view class="blockContent"> ?? ??? ??? ??? ??? ??? ??? ??? ?<text>第{{index + 1}}塊內(nèi)容</text> ?? ??? ??? ??? ??? ??? ??? ?</view> ?? ??? ??? ??? ??? ??? ?</view> ?? ??? ??? ??? ??? ?</block> ?? ??? ??? ??? ?</view> ?? ??? ??? ?</scroll-view> ?? ??? ?<!--滾動(dòng)條部分--> ?? ??? ?<view class="slide" wx:if="{{slideShow}}"> ?? ??? ??? ?<view class='slide-bar'> ?? ??? ??? ??? ?<view class="slide-show" style="width:{{slideWidth}}rpx; margin-left:{{slideLeft<=1 ? 0 : slideLeft+'rpx'}};"></view> ?? ??? ??? ?</view> ?? ??? ?</view> ?? ?</view> </view>
index.js
const app = getApp() Page({ ? data: { ? ? // 滑動(dòng)比例計(jì)算 ? ? slideWidth: '', //滑塊寬 ? ? slideLeft: 0, //滑塊位置 ? ? totalLength: '', //當(dāng)前滾動(dòng)列表總長(zhǎng) ? ? slideShow: false, //滑塊是否顯示 ? ? slideRatio: '', //滑塊比例 ? ? // 渲染數(shù)據(jù) ? ? dataList: [{ ? ? ? ? text: '第1塊' ? ? ? },{ ? ? ? ? text: '第2塊' ? ? ? }, { ? ? ? ? text: '第3塊' ? ? ? },{ ? ? ? ? text: '第4塊' ? ? ? },{ ? ? ? ? text: '第5塊' ? ? ? },{ ? ? ? ? text: '第6塊' ? ? ? }], ? }, ? onLoad: function () { ? ? // 這里是獲取視口口寬度 ? ? var systemInfo = wx.getSystemInfoSync(); ? ? this.setData({ ? ? ? windowWidth: systemInfo.windowWidth, ? ? }) ? ? this.getRatio() ? }, ? getRatio() { ? ? if (this.data.dataList.length < 4) { ? ? ? this.setData({ ? ? ? ? slideShow: false ? ? ? }) ? ? } else { ? ? ? var _totalLength = this.data.dataList.length * 173; //分類列表總長(zhǎng)度 ? ? ? var _ratio = 80 / _totalLength * (750 / this.data.windowWidth); //滾動(dòng)列表長(zhǎng)度與滑條長(zhǎng)度比例 ? ? ? var _showLength = 750 / _totalLength * 80; //當(dāng)前顯示藍(lán)色滑條的長(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
.hotService{ ? width: 100%; ? height: 300rpx; ? background-color: #fff; ? padding: 0 26rpx; ? box-sizing: border-box; } .hotServiceList_box { ? position: relative; ? overflow: hidden; ? white-space: nowrap; ? width: 100%; } .block { ? width: 158rpx; ? height: 158rpx; ? padding: 0 10rpx; ? display: inline-block; ? } .blockContent{ ? width: 100%; ? height: 100%; ? background-color: rgb(101, 203, 243); ? color:#fff; ? display: flex; ? justify-content: center; ? align-items: center; } .block:first-child { ? padding: 0 15rpx 0 0; } .slide{ ? height: 20rpx; ? background:#fff; ? width:100%; ? padding:14rpx 0 5rpx 0 ?} ?.slide .slide-bar{ ? width: 80rpx; ? margin:0 auto; ? height: 10rpx; ? background:#eee; ? border-radius: 8rpx; ?} ?.slide .slide-bar .slide-show{ ? height:100%; ? border-radius: 8rpx; ? background-color: #00aeff; ?}
index.json
{ ? "usingComponents": {} }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?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)條不顯示的方法示例
- 微信小程序scroll-view仿拼多多橫向滑動(dòng)滾動(dòng)條
- 微信小程序-橫向滑動(dòng)scroll-view隱藏滾動(dòng)條
- 微信小程序 scroll-view隱藏滾動(dòng)條詳解
- 微信小程序scroll-view實(shí)現(xiàn)自定義滾動(dòng)條
相關(guān)文章
js判斷手機(jī)號(hào)是否正確并返回的實(shí)現(xiàn)代碼
這篇文章主要介紹了js判斷手機(jī)號(hào)是否正確并返回的實(shí)現(xiàn)代碼,以及使用正則表達(dá)式判斷手機(jī)號(hào)是否正確,需要的的朋友參考下2017-01-01微信小程序MUI側(cè)滑導(dǎo)航菜單示例(Popup彈出式,左側(cè)滑動(dòng),右側(cè)不動(dòng))
這篇文章主要介紹了微信小程序MUI側(cè)滑導(dǎo)航菜單,結(jié)合實(shí)例形式分析了微信小程序Popup彈出式,左側(cè)滑動(dòng),右側(cè)不動(dòng)菜單功能相關(guān)實(shí)現(xiàn)技巧與注意事項(xiàng),需要的朋友可以參考下2019-01-01使用typescript改造koa開發(fā)框架的實(shí)現(xiàn)
這篇文章主要介紹了使用typescript改造koa開發(fā)框架的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02原生javascript實(shí)現(xiàn)文件異步上傳的實(shí)例講解
下面小編就為大家?guī)硪黄鷍avascript實(shí)現(xiàn)文件異步上傳的實(shí)例講解。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-10-10BootstrapTable+KnockoutJS自定義T4模板快速生成增刪改查頁(yè)面
這篇文章主要介紹了BootstrapTable+KnockoutJS自定義T4模板快速生成增刪改查頁(yè)面 的相關(guān)資料,需要的朋友可以參考下2016-08-08瀏覽器解析js生成的html出現(xiàn)樣式問題的解決方法
接觸css, javascript有三年多了,今天遇到的問題最令我不可思議,很容易給人一種錯(cuò)覺,那就是js拼成的html結(jié)構(gòu)肯定有問題2012-04-04JS實(shí)現(xiàn)簡(jiǎn)易留言板增刪功能
這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)簡(jiǎn)易留言板增刪功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02