小編給大家分享一下微信小程序中選項(xiàng)卡的實(shí)現(xiàn)方法,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
上猶網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、自適應(yīng)網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營(yíng)維護(hù)。成都創(chuàng)新互聯(lián)公司自2013年創(chuàng)立以來(lái)到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)公司。
之前寫過(guò)基于swiper的選項(xiàng)卡,在小程序中有swiper組件,毫無(wú)疑問(wèn)這里要用到swiper組件
小程序中的swiper組件有個(gè)問(wèn)題就是不能根據(jù)內(nèi)容自適應(yīng)高度,所以要通過(guò)wx.getSystemInfoSync獲取設(shè)備高度設(shè)置swiper高度
小程序中的swiper組件中swiper-item內(nèi)容超出可視區(qū)后無(wú)法滾動(dòng)顯示,所以這里要用到另一個(gè)組件scroll-view。
小程序中的swiper組件功能還是比較有限的,有待優(yōu)化。
data: { tabs: ['菜單一', '菜單二'],// 導(dǎo)航菜單欄 curIdx:0,// 當(dāng)前導(dǎo)航索引 scrollHeight:0, //滾動(dòng)高度 = 設(shè)備可視區(qū)高度 - 導(dǎo)航欄高度 list:[],// 內(nèi)容區(qū)列表 },
在onLoad函數(shù)中填充數(shù)據(jù)
/** * 生命周期函數(shù)--監(jiān)聽頁(yè)面加載 */ onLoad: function (options) { let list=[]; for (let i=1;i<=30;i++){ list.push(i) } this.setData({ list: list }); },
<!-- 導(dǎo)航欄開始 --> <view class="swiper-tab"> <view wx:for="{{tabs}}" wx:key class="swiper-tab-item {{curIdx==index?'swiper-active':''}}" data-current="{{index}}" catchtap="clickTab"> <text>{{item}}</text> </view> </view>
/*初始化樣式*/ view, text, picker, input, button, image{ display: flex; box-sizing: border-box; } /* 導(dǎo)航樣式*/ .swiper-tab { position: relative; width: 100%; height: 100rpx; justify-content: center; align-items: center; } .swiper-tab-item { background-color: #f3f3f3; width: 50%; height: 80rpx; justify-content: center; align-items: center; } .swiper-active{ background-color: rgb(129, 190, 247); color: #fff; }
內(nèi)容顯示區(qū)使用swiper組件,swiper-item個(gè)數(shù)要與tabs數(shù)組長(zhǎng)度 一致
<!-- 內(nèi)容開始 --> <swiper class="swiper_content" current="{{curIdx}}" bindchange="swiperTab" style='height:{{scrollHeight}}px'> <swiper-item> <scroll-view class="scroll-y" scroll-y style='height:{{scrollHeight}}px' bindscrolltolower="onReachBottom"> <view wx:for="{{list}}" wx:key> <text> 內(nèi)容一{{item}}</text> </view> </scroll-view> </swiper-item> <swiper-item> 內(nèi)容二 </swiper-item> </swiper>
小程序中的swiper組件有個(gè)問(wèn)題就是不能根據(jù)內(nèi)容自適應(yīng)高度,所以要通過(guò)[wx.getSystemInfoSync][4]獲取設(shè)備高度設(shè)置swiper高度
小程序中的swiper組件中swiper-item內(nèi)容超出可視區(qū)后無(wú)法滾動(dòng)顯示,所以這里要用到另一個(gè)組件[scroll-view][5]。
我們?cè)趏nShow函數(shù)中通過(guò)getSystemInfoSync獲取設(shè)備的寬高來(lái)設(shè)置swiper組件高度以及scroll-view高度
onShow: function () { // 100為導(dǎo)航欄swiper-tab 的高度 this.setData({ scrollHeight: wx.getSystemInfoSync().windowHeight - (wx.getSystemInfoSync().windowWidth / 750 * 100), }) },
//點(diǎn)擊切換 clickTab: function (e) { this.setData({ curIdx: e.currentTarget.dataset.current }) },
//滑動(dòng)切換 swiperTab: function (e) { this.setData({ curIdx: e.detail.current }); },
/** * 頁(yè)面上拉觸底事件的處理函數(shù) */ onReachBottom: function () { // 更新列表 let list = this.data.list; console.log(list) let lens = list.length for (let i = lens; i < lens+30; i++) { list.push(i) } this.setData({ list: list }); },
看完了這篇文章,相信你對(duì)“微信小程序中選項(xiàng)卡的實(shí)現(xiàn)方法”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
分享題目:微信小程序中選項(xiàng)卡的實(shí)現(xiàn)方法
分享鏈接:http://m.2m8n56k.cn/article4/jdccoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、做網(wǎng)站、App設(shè)計(jì)、微信公眾號(hào)、Google、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)