微信小程序 滚动选项卡 swiper高度自适应
生活随笔
收集整理的這篇文章主要介紹了
微信小程序 滚动选项卡 swiper高度自适应
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
最近做小程序的時(shí)候遇到了swiper高度的問(wèn)題,swiper里面的內(nèi)容可以根據(jù)數(shù)據(jù)來(lái)自適應(yīng)高度。那就給scroll-view計(jì)算一下高度
wxml
js中
data:{// tab切換currentTab: 0,// nav: [{text: '首頁(yè)'},{text: '我的'},{text: '發(fā)布'},{text: '職場(chǎng)'},{text: '育兒'},{text: '糾紛'},],cons: [{name: "紀(jì)念卡",time: "2018-12-04 ",list: "首頁(yè)",},{name: "張三",time: "2018-12-04 12:00",ren: "我的",},{name: "張三",time: "2018-12-04 12:00",list: "發(fā)布",},{name: "張三",time: "2018-12-04 12:00",list: "情感",},{name: "張三",time: "2018-12-04 12:00",list: "糾紛",},],height: 0,widHeight: 0,navs: 0 } // 滾動(dòng)列表switch(e) {var that = thisvar cur = e.currentTarget.dataset.current;var width = this.data.windowWidth / 5; that .setData({navs: (cur - 2) * width })if (that .data.currentTab == cur) {return false;} else {that .setData({currentTab: cur})}},switchTab(e) {var cur = e.detail.current;var width = this.data.windowWidth / 5;this.setData({currentTab: cur,navs: (cur - 2) * width });},在onLond或者onShow中
//獲取swiper高度 var query = wx.createSelectorQuery();var that = this;var conents= this.data.cons.length;query.select('.payment').boundingClientRect(function (rect) {that.setData({height: rect.height,widHeight: rect.height * conents+ "px"})}).exec();},swiperTab: function (e) {var that = thisvar current=e.detail.currentvar heights = this.data.height;var conents= this.data.cons.lengththat.setData({currentTab: current});if (this.data.currentTab == 0) {that.setData({widHeight: heights * conents+ "px"});} },總結(jié)
以上是生活随笔為你收集整理的微信小程序 滚动选项卡 swiper高度自适应的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 实际操作之路考的这些事
- 下一篇: 科目三路考操作要点