如何实现元素半圆形排列

如何实现如下图的元素半圆形排列:

实现一个半圆形元素排列如图

在这里插入图片描述


<template>
  <div class="demo">
    <ul class="ul">
      <li
        v-for="(item, index) in transform"
        :key="item"
        :style="{ transform: item }"
      >
        <div class="li">
          <p>
            {{ index + 1 }}
          </p>
        </div>
      </li>
    </ul>
  </div>
</template>
<template>
  <div class="demo">
    <ul class="ul">
      <li
        v-for="(item, index) in transform"
        :key="item"
        :style="{ transform: item }"
      >
        <div class="li">
          <p>
            {{ index + 1 }}
          </p>
        </div>
      </li>
    </ul>
  </div>
</template>
  <script>
export default {
  data() {
    return {};
  },
  computed: {
    transform() {
      // let num = 5;
      // let angle = 180 / num;
      let arr = [270, 315, 0, 45, 90];
      // 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(${240 * Math.sin((angle * Math.PI) / 180) + 240}px, ${
        240 - 240 * Math.cos((angle * Math.PI) / 180)
      }px)`;
    },
  },
};
</script>
<style lang="less" scoped>
.demo {
  padding: 100px;
  box-sizing: border-box;
}
ul,
li {
  margin: 0;
  list-style-type: none;
  padding: 0;
}
ul {
  width: 480px;
  height: 480px;
  background-color: #fff;
  border-radius: 50%;
  position: relative;
  // transform: rotateZ(-70deg);
}
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;
  margin-left: -40px;
  margin-top: -40px;
  transform-origin: 0px 0px;
  .li {
    animation-name: shake;
    animation-duration: 5s;
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
  }
  p {
    display: block;
    width: 50px;
    height: 50px;
    background-color: aqua;
    line-height: 50px;
  }
}
@keyframes shake {
  /* 抖动动画 */
  0% {
    transform: translateY(0);
  }
  10%,
  30%,
  50%,
  70%,
  90% {
    transform: translateY(10px);
  }
  20%,
  40%,
  60%,
  80% {
    transform: translateY(-10px);
  }
  100% {
    transform: translateY(0);
  }
}
</style>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值