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

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.dtcms.com/a/153168.html

相关文章:

  • 深度解析 TransmittableThreadLocal(TTL):原理、实战与优化指南
  • Node.js 学习入门指南
  • Linux 内核 IPv4 套接字创建机制与协议表管理深度解析
  • 全链路数据仓建设指南:从构建流程到应用场景
  • 银河麒麟系统安装vscode
  • 2023 国考
  • JAVA中包装类型的数值比较问题
  • SPH Engineering - 无人机技术开发专家
  • shell脚本2
  • k8s基于角色的访问控制(RBAC)
  • 使用ffmpeg 将图片合成为视频,填充模糊背景,并添加两段音乐
  • SiamFC算法深度解析
  • 解决微信开发者工具报错 “Component is not found in path wx://not-found“ 代码修改后热更新报错
  • 【无人机】无人机遥控器设置与校准,飞行模式的选择,无线电控制 (RC) 设置
  • 被封号如何申诉?Google Play开发者账号申诉模版分享
  • ERROR: x264 not found using pkg-config
  • CS144 Lab 6 实战记录:构建 IP 路由器
  • Android学习总结之扩展基础篇(一)
  • AI数字人多模态技术如何提升用户体验?
  • c++——内部类
  • 自由学习记录(57)
  • 2025.5.4机器学习笔记:PINN文献阅读
  • 第53讲 农学科研中的AI伦理与可解释性——探索SHAP值、LIME等可解释工具与科研可信性建设之道
  • 【棒球运动】户外运动安全技巧·棒球1号位
  • 【操作系统间文件共享_Samba】三、Samba 在实际场景中的应用案例与故障排除
  • Multi-granular Adversarial Attacksagainst Black-box Neural Ranking Models--阅读笔记
  • 制造工厂如何借助电子看板实现高效生产管控
  • 高可靠性厚铜板制造的关键设备与工艺投入
  • femap许可不足如何解决
  • [flutter]切换国内源(window)