<image src=
"url" class=
"imgClass" model=
"aspectFit" bindload=
"imageLoad" />
1.以前将小程序图片宽度设置为屏幕宽度:
imageLoad:
function () {
this.setData({
imageWidth: wx.getSystemInfoSync().windowWidth
})
}
2.现在:
.imgClass{
width: 100vw;
}
解析: css3引入的”vw”和”vh”基于宽度/高度相对于窗口大小 ”vw”=”view width”“vh”=”view height” 以上我们称为视窗单位允许我们更接近浏览器窗口来定义大小。 参照demo案例对照下面四个容器的css样式:
.demo {
width: 100vw;
font-size: 10vw;
}
.demo1 {
width: 80vw;
font-size: 8vw;
}
.demo2 {
width: 50vw;
font-size: 5vw;
}
.demo3 {
width: 10vw;
height: 50vh;
}