微信小程序,利用wx.createSelectorQuery动态设置swiper或者scroll-view的高度做手机适配

 <scroll-view scroll-y   style="height:{{scrollHeight}}px">
       // 计算滚动高度
        var windowHeight = that.data.windowHeight;
        var headerHeight ;
        wx.createSelectorQuery().selectAll('.mine_header').boundingClientRect(function (rects) {
            rects.forEach(function (rect) {
           
                headerHeight= (rect.height)+25;
                console.log(headerHeight)
            })
            that.setData({
                scrollHeight: windowHeight - headerHeight,
              
            })
            console.log('本次高度' + that.data.scrollHeight)
        }).exec()

获取屏幕高度 再减去除了srcoll区域之外的所有容器高度 得出最后的高度 在设置高度内滚动内容如图:

猜你喜欢

转载自blog.csdn.net/qinyongqaq/article/details/86702345