微信小程序如何获取屏幕宽度

微信小程序如何获取屏幕宽度

   方法1:

imageLoad: function () {
   this.setData({
     imageWidth: wx.getSystemInfoSync().windowWidth
   })
 }

   方法2:

.imgClass{
 width: 100vw;
}

CSS3引入的”vw”和”vh”基于宽度/高度相对于窗口大小 

”vw”=”view width”“vh”=”view height” 

以上我们称为视窗单位允许我们更接近浏览器窗口来定义大小。

.demo {
  width: 100vw;
  font-size: 10vw; /* 宽度为窗口100%, 字体大小为窗口的10% */
}
.demo1 {
  width: 80vw;
  font-size: 8vw; /* 宽度为窗口80%, 字体大小为窗口的8% */
}
.demo2 {
  width: 50vw;
  font-size: 5vw; /* 宽度为窗口50%, 字体大小为窗口的5% */
}
.demo3 {
  width: 10vw;
  height: 50vh; /* 宽度为窗口10%, 容器高度为窗口的50% */
}

转:https://blog.csdn.net/kerryqpw/article/details/78802023

 

猜你喜欢

转载自www.cnblogs.com/fps2tao/p/10119112.html