动态计算页面的高度

2020-03-23  本文已影响0人  Eayon_Dong

获取屏幕高度信息

  data: {
    width: 0,
    height: 0
  },

onShow: function() {
  // 获取屏幕尺寸宽度高度
  var height = wx.getSystemInfoSync().windowHeight
  var width = wx.getSystemInfoSync().windowWidth
  // 保存到模型层
  this.setData({
    height: height,
    width: width
  })
  console.log(height)
}

页面上设置一个\color{red}{swiper}属性, 引用上面模型层中的高度变量. 这样\color{red}{swiper}控件就可以适配屏幕的高度了.

<swiper class="swiper" style="height: {{height}}px">
</swiper>
上一篇 下一篇

猜你喜欢

热点阅读