当前位置: 首页 > ds >正文

uniapp 仿小红书轮播图效果

通过对小红书的轮播图分析,可得出以下总结:

1.单张图片时容器根据图片像素定高
2.多图时轮播图容器高度以首图为锚点
3.比首图长则固高左右留白
4.比首图短则固宽上下留白

代码如下:

<template><view>
<!--轮播--><swiperclass="swiper" :style="{ 'height': swiperHeight+ 'px' }"circular:indicator-dots="indicatorDots":autoplay="autoplay":interval="interval":duration="duration"indicator-active-color="#FFFFFF"><swiper-item v-for="(item, index) in imgList" :key="index" ><image class="swiper-image" :src="item" mode="aspectFit" @click="showImage(index)" :style="{ 'height': swiperHeight+ 'px' }"/></swiper-item></swiper></view>
</template>export default {data() {return {indicatorDots: true,autoplay: true,interval: 5000,duration: 300,imgList: ["https://mainoss.duoxiaiche.com/UNCATEGORIZED/1745480113402.jpg", "https://mainoss.duoxiaiche.com/UNCATEGORIZED/1745480117425.jpg", "https://mainoss.duoxiaiche.com/UNCATEGORIZED/1745480122350.jpg"],swiperHeight:400,//默认高度}},onLoad() {const firstImg = this.imgList[0] || ''this.getImgHeight(firstImg).then((heightRes) => {this.swiperHeight = heightRes})},methods: {getImgHeight(imageUrl){let containerHeight = 400return new Promise((resolve, reject) => {wx.getImageInfo({src: imageUrl,success: (res) => {const { width, height } = resuni.getSystemInfo({success: (res) => {const screenWidth = res.windowWidth;const aspectRatio = width / height;const imgHeight = screenWidth / aspectRatio;console.log('imgHeight---',imgHeight)containerHeight = imgHeight && imgHeight < 400 ? imgHeight : 400;resolve(containerHeight)},})},fail: (err) => {console.error('Failed to get image info', err)reject(containerHeight)},})})},// 点击显示图片showImage(index) {uni.previewImage({urls: this.imgList,current: index,indicator: 'number'});},}}
</script><style lang="scss" scoped>
.swiper {.swiper-image {width: 100%;}
}
</style>

效果图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

http://www.xdnf.cn/news/1770.html

相关文章:

  • Spring Boot 配置处理器深度解析:元数据驱动的工程实践
  • 从零开始:CTF中的XSS漏洞入门指南
  • 【OSG学习笔记】Day 7: 材质与光照——让模型“活”起来
  • 09前端项目----分页功能
  • open公司环境链接搭建代理和转发
  • oracle 锁的添加方式和死锁的解决
  • 企业为何要求禁用缺省口令?安全风险及应对措施分析
  • 【文献速递】NMR代谢组寻找预测DR发展的候选标志物
  • ‌RISC-V低功耗MCU动态时钟门控技术详解
  • go gin框架ShouldBindJSON不能接受’0‘值
  • js 的call 和apply方法用处
  • NeRF:原理 + 实现 + 实践全流程配置+数据集测试【Ubuntu20.04 】【2025最新版】
  • 3D模型文件格式之《glb/gltf格式介绍》
  • PostgreSQL 中的权限视图
  • Qt 中线程使用
  • 国产操作系统-招标公司专家随机抽选系统————仙盟创梦IDE开发
  • 以运营为核心的智能劳动力管理系统,破解连锁零售、制造业排班难题
  • 2020-06-23 暑期学习日更计划(机器学习入门之路(资源汇总)+概率论)
  • Android插拔U盘导致黑屏问题排查
  • 陪诊陪检系统源码,陪诊小程序,陪诊APP,陪诊服务,家政上门系统,居家护理陪护源码,医护小程序
  • 使用正确的 JVM 功能加速现有部署
  • 文本溢出隐藏显示省略号
  • 【办公类-89-02】20250424会议记录模版WORD自动添加空格补全下划线
  • Windows 强制删除文件夹/文件(删除提示“你需要来自 Administrators 的权限才能对此文件夹进行更改”)
  • Linux电源管理(四),设备的Runtime Power Management(RPM)
  • Oracle锁的概念和类型
  • SiamMask原理详解:从SiamFC到SiamRPN++,再到多任务分支设计
  • 数值数据标准化:机器学习中的关键预处理技术
  • 数据分析之 商品价格分层之添加价格带
  • 项目管理、项目集管理与项目组合管理的区别与管理策略解析