wxml:
<!-- banner图 -->
<swiper style="height:{
{imgHeight[current]}}rpx;" bindchange="bindchange">
<block wx:for="{
{imgUrls}}" wx:key="that">
<swiper-item>
<image src="{
{item.img_url+webp}}" class="slide-image" mode='aspectFill' data-url="{
{item.link}}" bindload="imageLoad" bindtap='goto' data-id="{
{index}}" />
</swiper-item>
</block>
</swiper>
wxss::由于swiper的高度在变化,所以需要加一个过渡动画。
.swiper-box {
position: relative;
transition: height ease-out 0.2s;
}
.slide-image {
width: 100%;
height: 100%;
}
js:
data: {
//所有图片的高度
imgHeight: [],
//图片宽度
imgwidth: 750,
//默认
current: 0
},
imageLoad: function (e) {//获取图片真实宽度
var imgwidth = e.detail.width,
imgheight = e.detail.height,
//宽