swiper高度自适应

发布于 7 年前作者 fang961021 次浏览最后编辑 7 年前来自 ask

swiper高度怎么自适应

3 回复
jiafang
jiafang1 楼6 年前

请问问题解决了吗,我也遇到了swiper 高度无法由内容撑开的问题。

fang88
fang882 楼6 年前

< swiper wx:for='{{array}}' style = 'height:{{ heights[index] || 50 }}px' > 

     < swiper-item > 

         < view class = 'getThisHeight' > 

            ...这里放自适应内容 

         </ view > 

     </ swiper-item > 

</ swiper > 


justifyHeight:  function () { 

     let that =  this 

     let hs = [] 

    wx.createSelectorQuery().selectAll( '. getThisHeight ' ).boundingClientRect( function (rects) { 

        rects.forEach((v, i) => { 

            hs[i] = v.height 

        }) 

        that.setData({ 

            heights: hs, 

        }) 

    }).exec() 

},

lhe
lhe3 楼5 年前

小试了下,

swiper 不支持 :before,

也不受 css 的百分比高度或 flex:1 影响,

改 swiper-item 高度又不影响父级…

话说如果是随屏宽自适应的话,rpx 是可以满足的,

但如果是随其他元素高度变化而自适应的话,恐怕只能 js 了。