美文网首页
动态计算页面的高度

动态计算页面的高度

作者: Eayon_Dong | 来源:发表于2020-03-23 15:58 被阅读0次

获取屏幕高度信息

  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>

相关文章

网友评论

      本文标题:动态计算页面的高度

      本文链接:https://www.haomeiwen.com/subject/oepwyhtx.html