there is no adaptive picture height in Mini Program
writes a goodsList component. According to the return situation of the background, there are two formats: video and image.
goodsList.wxml
<view class="goods-container">
<view class="goods-lists">
<cover-view
class="goods-list"
wx:for="{{goodsList}}"
wx:key="{{index}}"
style="height:{{item.height}}">
<cover-view
wx:if="{{item.type === 1}}"
style="height:{{item.height}};width:{{item.width}}">
<cover-image
data-index="{{index}}"
src="{{item.imgPath}}"
mode="widthFix"
bindload="imageLoad"
></cover-image>
</cover-view>
<view wx:else >
<video
src="{{item.videoPath}}"
></video>
</view>
</cover-view>
</view>
</view>
goodsList.wxss
.goods-lists{
height: 100%;
display: flex;
flex-wrap: wrap;
}
.goods-list{
width: 344rpx;
margin-right: 22rpx;
}
.goods-list:nth-of-type(2n){
margin-right: 0;
}
.goods-list video{
width: 100%;
}
.goods-list image{
width: 100%;
height: 100%;
}
use
in a file<view class="main">
<view class="share-title c3 fz28">TA</view>
<goods-list goods-list="{{goodsList}}" bind:imageLoad="imageLoad"></goods-list>
</view>
imageLoad: function(e){
//
const orgionWidth = e.detail.detail.width,
orgionHeight = e.detail.detail.height;
const ratio = orgionWidth / orgionHeight;
console.log(orgionWidth,orgionHeight,ratio);
//
const width = 344,
heigth = 344 / ratio;
//
const index = e.detail.target.dataset.index;
let imgs = this.data.goodsList;
if (orgionWidth > width){
imgs[index].height = heigth +"rpx";
imgs[index].width = width + "rpx";
}else{
imgs[index].height = orgionWidth + "rpx";
imgs[index].width = orgionHeight + "rpx";
}
this.setData({
goodsList: imgs
})
}
but the last one is this
the following picture is supposed to be on top.