圆形环绕排列

需求:有多个圆形环绕中间的圆形排列

代码:

<template>
  <div class="demo">
    <ul>
      <li v-for="(item,index) in transform" :key="item" :style="{transform: item}">{{index+1}}</li>
    </ul>
  </div>
</template>

 

export default {
  computed: {
    transform() {
      let num = 11
      let angle = 360/num
      let arr = []
      for (let index = 0; index < num; index++) {
        arr.push(index*angle)
      }
      arr = arr.map(d => this.getAxis(d) )
      return arr
    }
  },
  methods: {
    getAxis(angle) {
      // 公式,r-半径,angle-角度
      // x: r+r*Math.sin(angle*Math.PI/180)
      // y: r-r*Math.cos(angle*Math.PI/180)
      return `translate(${200*Math.sin(angle*Math.PI/180)+200}px, ${200-200*Math.cos(angle*Math.PI/180)}px)`
    }
  }
}
.demo {
  width: 600px;
  height: 600px;
  background-color: rgb(255, 195, 195);
  padding: 100px;
  box-sizing: border-box;
}
ul,
li {
  margin: 0;
  list-style-type: none;
  padding: 0;
}
ul {
  width: 400px;
  height: 400px;
  background-color: #fff;
  border-radius: 50%;
  position: relative;
}
li {
  width: 80px;
  height: 80px;
  position: absolute;
  background-color: rgb(97, 153, 74);
  color: white;
  font-size: 25px;
  border-radius: 50%;
  line-height: 80px;
  text-align: center;
  /* left: 50%; */
  margin-left: -40px;
  margin-top: -40px;
  transform-origin: 0px 0px;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值