swiper高度自适应
发布于 6 年前 作者 fang96 876 次浏览 来自 问答

swiper高度怎么自适应

3 回复

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

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() 

},

小试了下,

swiper 不支持 :before,

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

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

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

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

回到顶部