鍍金池/ 問答/HTML5  PHP  HTML/ 微信小程序swiper問題

微信小程序swiper問題

clipboard.png
先上圖一張 這是需要做到的效果

因為小程序的swiper都固定了一個高度,所以寫了一個取swiper-item內容的高度,可是一直都不對,找不到原因,求各位大神幫忙看看

     <swiper indicator-dots="{{indicatorDots}}"duration="{{duration}}" indicator-color="#fff" indicator-active-color="#f30" style='height:{{Height}}px'>
  <block wx:for="{{channel}}">
    <swiper-item >
 <view class="featured goods-list"  id='channelSwiper'>
  <text>{{item.channeltitle}}</text>
     <view class='module-banner'><image src='{{item.moduleBanner}}' mode="widthFix"></image></view>
      <view class="list-view-cell"wx:for="{{goodsList}}">
   <image src='{{item.imgwrap}}' mode="widthFix" class='imgwrap'></image>
    </view>
     </view>
    </swiper-item>
  </block>
</swiper>
Page({
  data: {
    Height:0,
    indicatorDots: true,
    autoplay: true,
    interval: 4500,
    duration: 1000,
    channel: [{
      "moduleBanner": "image/module-banner (1).jpg",
      "channeltitle": "標題1",
    },
      {
        "moduleBanner": "image/module-banner (2).jpg",
        "channeltitle": "標題2",
      }
    ],
    goodsList: [{
      "imgwrap": "image/goods (1).jpg",
    },
    {
      "imgwrap": "image/goods (2).jpg",
    },
    {
      "imgwrap": "image/goods (3).jpg",
    }
    ]
  },
  onReady: function () {
    var Vheight = 0;
    var that = this;
    var query = wx.createSelectorQuery()
    query.select('#channelSwiper').boundingClientRect(function (rect) {
      rect.height  // 節(jié)點的高度
      Vheight = rect.height;
      that.setData({
        Height: Vheight
      })
      console.log("高度" + Vheight);
    }).exec();
  },
   changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  }
})
.list-view-cell{
  width: 33.3%;
  display: inline-block
}
.module-banner>image{
  width: 100%
}

圖片描述

這是效果圖,請注意右下角打印的高度,一直不對甚至多出來很多多余的高度,求問是什么原因

回答
編輯回答
扯機薄

外面多嵌套一層設置樣式,是不是可以解決

2017年12月9日 11:02
編輯回答
祉小皓

小程序里swiper默認是400rpx高,swiper-item 的height是100%;
你把這兩個高度改成auto,讓他倆高度靠子元素撐高,小程序里image 有默認高度240px你也得對應改一下

2017年11月16日 02:42