欢迎您光临09模板资源网
当前位置:首页 > 教程

uniapp轮播图父元素自适应图片高度

09模板网 2024-12-19 0

uniapp轮播图父元素自适应图片高度

template

<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
      :duration="duration" indicator-color='rgba(255, 255, 255, 0.3)' indicator-active-color="#FFFFFF" :style="{ height: swiperHeight + 'px' }">
    <swiper-item v-for="(item, i) in swlist" :key="i">
        <image :src="item.thumb" mode="widthFix" @load="imageLoaded"></image>
    </swiper-item>
</swiper>

script

data() {
    return {

        swiperHeight: 0,
        imageHeights: []
    }
},

方法

methods: {
    imageLoaded(e) {
        const height = e.detail.height;
        const width = e.detail.width;
        // 设置swiper的宽度为屏幕宽度,并计算swiper的高度
        const swiperWidth = uni.getSystemInfoSync().windowWidth;
        const scale = width / swiperWidth;
        const imageHeight = height / scale;
        this.swiperHeight = Math.max(this.swiperHeight, imageHeight);
        this.imageHeights.push(imageHeight);
    },
}


声明:

本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

加入本站VIP会员订阅计划,海量资源免费下载查看

目前为止共有 1388 位优秀的VIP会员加入! 立即加入VIP会员