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

uni-app:实现图片周围的图片按照圆进行展示

效果

代码

<template><view class="position"><view class="circle"><img src="/static/item1.png" class="center-image"><view v-for="(item, index) in itemList" :key="index" class="item" :style="getItemStyle(index)"><img :src="item.src" /><text>{{ item.name }}</text></view></view></view>
</template><script>export default {data() {return {itemList: [{name: "Item1",src: "/static/item1.png"},{name: "Item2",src: "/static/item2.png"},{name: "Item3",src: "/static/item3.png"},{name: "Item4",src: "/static/item4.png"},{name: "Item5",src: "/static/item5.png"},{name: "Item6",src: "/static/item6.png"},{name: "Item7",src: "/static/item7.png"},],circleRadius: 120, // 圆的半径itemSize: 60, // 每个view的大小};},methods: {// 计算每个 view 的样式getItemStyle(index) {const {itemList,circleRadius,itemSize} = this;const angle = (2 * Math.PI) / itemList.length; // 每个 view 的角度间隔const centerX = circleRadius + itemSize / 2; // 圆心的 x 坐标const centerY = circleRadius + itemSize / 2; // 圆心的 y 坐标const radius = circleRadius + itemSize / 2; // view 的圆心距离(圆的半径加上 view 大小的一半)const x = Math.round(centerX + radius * Math.cos(angle * index - Math.PI / 2)); // 计算 x 坐标const y = Math.round(centerY + radius * Math.sin(angle * index - Math.PI / 2)); // 计算 y 坐标return {width: itemSize + "px",height: itemSize + "px",position: "absolute",top: y + "px",left: x + "px",transform: `translate(-50%, -50%)`, // 居中显示};},},};
</script><style scoped>/* 整体位置 */.position{/* border: 1px solid black; */position: absolute;top:50%;left:50%;transform: translate(-50%, -50%);}/* 圆的样式 */.circle {width: 300px;height: 300px;border-radius: 50%;/* border: 1px solid black; */}/* 中间图标 */.center-image {width: 80px;height: 80px;position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);}/* 小图标 */.item {display: flex;flex-direction: column;align-items: center;justify-content: center;text-align: center;}/* 小图标的图片信息 */.item img {width: 40px;height: 40px;border-radius: 50%;}
</style>

http://www.lryc.cn/news/177200.html

相关文章:

  • Django之视图
  • 【软件工程_设计模式】——为什么要使用设计模式?
  • 大数据之Kafka
  • 灵活运用OSI模型提升排错能力
  • 【最新!企知道AES加密分析】使用Python实现完整解密算法
  • 前端架构师之11_JavaScript事件
  • 文本过滤工具:grep
  • 【Linux】生产者和消费者模型
  • 开发APP的费用是多少
  • start()方法源码分析
  • VUE_history模式下页面404错误
  • 现代数据架构-湖仓一体
  • 最新AI写作系统ChatGPT源码/支持GPT4.0+GPT联网提问/支持ai绘画Midjourney+Prompt应用+MJ以图生图+思维导图生成
  • Python机器学习实战-特征重要性分析方法(5):递归特征消除(附源码和实现效果)
  • 如何快速走出网站沙盒期(关于优化百度SEO提升排名)
  • ATA-8000系列射频功率放大器——应用场景介绍
  • 2009-2018年各省涉农贷款数据(wind)
  • window.print()打印及出现的问题
  • Fedora Linux 39 Beta 预估 10 月底发布正式版
  • 【zookeeper】基于Linux环境安装zookeeper集群
  • 什么是IoT数字孪生?
  • 俄罗斯四大平台速卖通、Joom、Ozon 和 UMKA中国卖家如何脱颖而出!
  • destoon 调用第三方api接口
  • js中的类型转换
  • Oracle物化视图(Materialized View)
  • Spring 学习(九)整合 Mybatis
  • Android AMS——概述(一)
  • DDoS攻击和CC攻击
  • Lnmp架构之mysql数据库实战2
  • 【软件工程_设计模式Designer Method】三类?23种常用设计模式?-简介-作业一