vue 菜单旋转动画效果实现

vue yekong

在做大屏项目供水综合信息管理平台为了让大屏项目看起来更酷炫,根据设计图加入了一些自己觉得还可以的动画效果。

演示动画

vue 菜单旋转动画效果实现

实现代码

/**
* @Author: 858834013@qq.com
* @Name: top
* @Date: 2022-07-25
* @Desc:
*/
<template>
  <div class="topbg">
    <nav class="menu">
      <input type="checkbox" disabled :checked="checked" class="menu-toggler" id="menu_toggler">
      <!--      <label for="menu_toggler"></label>-->
      <ul>
        <li class="menu-item">
          <div class="menu-itemx">
            <p>提交申请</p>
            <rotateCenter>
              <img class="center_icon1" src="../../../assets/page/center_icon1.png" alt="">
            </rotateCenter>
          </div>
        </li>
        <li class="menu-item">
          <div class="menu-itemx">
            <rotateCenter>
              <img class="center_icon2" src="../../../assets/page/center_icon2.png" alt="">
            </rotateCenter>
            <p>审批退回</p>
          </div>
        </li>
        <li class="menu-item">
          <div class="menu-itemx">
            <rotateCenter>
              <img class="center_icon3" src="../../../assets/page/center_icon3.png" alt="">
            </rotateCenter>
            <p>完成</p>
          </div>
        </li>
        <li class="menu-item">
          <div class="menu-itemx">
            <rotateCenter>
              <img class="center_icon4" src="../../../assets/page/center_icon4.png" alt="">
            </rotateCenter>
            <p>执行中</p>
          </div>
        </li>
        <li class="menu-item">
          <div class="menu-itemx">
            <rotateCenter>
              <img class="center_icon5" src="../../../assets/page/center_icon5.png" alt="">
            </rotateCenter>
            <p>草稿</p>
          </div>
        </li>
      </ul>
    </nav>
  </div>
</template>

<script>
import rotateCenter from "@/components/rotateCenter";

export default {
  name: "top",
  components: {rotateCenter},
  props: {
    id: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      status: '',
      checked: false
    }
  },
  watch: {},

  mounted() {
    var that = this;
    setTimeout(() => {
      that.checked = true
    }, 1000)
  },
  methods: {}
}
</script>

<style lang="scss" scoped>
.topbg {
  width: 100%;
  position: relative;
  height: 100%;
  background: url('../../../assets/page/centerbg.png') center center no-repeat;
  background-size: 937px 754px;

  .menu-toggler {
    position: absolute;
    display: block;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    margin: auto;
    width: 40px;
    height: 40px;
    z-index: 2;
    opacity: 0;
    cursor: pointer;
  }

  .menu-toggler:hover + label,
  .menu-toggler:hover + label::before,
  .menu-toggler:hover + label::after {
    background: #fff;
  }

  .menu-toggler:checked + label {
    background: transparent;
  }

  .menu-toggler:checked + label::before,
  .menu-toggler:checked + label::after {
    top: 0;
    width: 40px;
    transform-origin: 50% 50%;
  }

  .menu-toggler:checked + label::before {
    transform: rotate(45deg);
  }

  .menu-toggler:checked + label::after {
    transform: rotate(-45deg);
  }

  .menu-toggler:checked ~ ul .menu-item {
    opacity: 1;

    p {
      font-size: 24px;
      font-family: PingFang;
      font-weight: bold;
      color: #24ECFD;
      white-space: nowrap;
    }
  }

  .menu-toggler:checked ~ ul .menu-item:nth-child(1) {
    transform: rotate(90deg) translateX(-240px);

    .menu-itemx {
      transform: rotate(-90deg);
      display: flex;
      justify-content: center;
      align-items: center;
      flex-wrap: nowrap;
      flex-direction: column;
      align-content: flex-start;
      margin-top: -48px;
    }
  }

  .menu-toggler:checked ~ ul .menu-item:nth-child(2) {
    transform: rotate(162deg) translateX(-240px);

    .menu-itemx {
      transform: rotate(-162deg);
      display: flex;
      justify-content: center;
      align-items: center;
      flex-wrap: nowrap;
      flex-direction: column;
      align-content: flex-start;
      margin-top: -40px;
    }
  }

  .menu-toggler:checked ~ ul .menu-item:nth-child(3) {
    transform: rotate(234deg) translateX(-240px);

    .menu-itemx {
      transform: rotate(-234deg);
      display: flex;
      justify-content: center;
      align-items: center;
      flex-wrap: nowrap;
      flex-direction: column;
      align-content: flex-start;
      margin-top: -30px;
    }
  }

  .menu-toggler:checked ~ ul .menu-item:nth-child(4) {
    transform: rotate(306deg) translateX(-230px);

    .menu-itemx {
      transform: rotate(-306deg);
      display: flex;
      justify-content: center;
      align-items: center;
      flex-wrap: nowrap;
      flex-direction: column;
      align-content: flex-start;
      margin-top: -48px;
    }
  }

  .menu-toggler:checked ~ ul .menu-item:nth-child(5) {
    transform: rotate(378deg) translateX(-230px);

    .menu-itemx {
      transform: rotate(-378deg);
      display: flex;
      justify-content: center;
      align-items: center;
      flex-wrap: nowrap;
      flex-direction: column;
      align-content: flex-start;
      margin-top: -30px;
    }
  }

  .menu-toggler:checked ~ ul .menu-item a {
    pointer-events: auto;
  }

  .menu-toggler + label {
    width: 40px;
    height: 5px;
    display: block;
    z-index: 1;
    border-radius: 2.5px;
    background: rgba(255, 255, 255, 0.7);
    transition: transform 0.5s, top 0.5s;
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    margin: auto;
  }

  .menu-toggler + label::before,
  .menu-toggler + label::after {
    width: 40px;
    height: 5px;
    display: block;
    z-index: 1;
    border-radius: 2.5px;
    background: rgba(255, 255, 255, 0.7);
    transition: transform 0.5s, top 0.5s;
    content: "";
    position: absolute;
    left: 0;
  }

  .menu-toggler + label::before {
    top: 10px;
  }

  .menu-toggler + label::after {
    top: -10px;
  }

  .menu-item:nth-child(1) a {
    transform: rotate(90deg);
  }

  .menu-item:nth-child(2) a {
    transform: rotate(-162deg);
  }

  .menu-item:nth-child(3) a {
    transform: rotate(-234deg);
  }

  .menu-item:nth-child(4) a {
    transform: rotate(-306deg);
  }

  .menu-item:nth-child(5) a {
    transform: rotate(-378deg);
  }

  .menu-item {
    position: absolute;
    display: block;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    width: 80px;
    height: 80px;
    opacity: 0;
    transition: 0.5s;
  }

  .menu-item a {
    display: block;
    width: inherit;
    height: inherit;
    line-height: 80px;
    color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    text-align: center;
    text-decoration: none;
    font-size: 40px;
    pointer-events: none;
    transition: 0.2s;
  }

  .menu-item a:hover {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
    color: #fff;
    background: rgba(255, 255, 255, 0.3);
    font-size: 45px;
  }
}

.center_icon1 {
  width: 41px;
  height: 36px;
}
.center_icon2 {
  width: 47px;
  height: 41px;
}
.center_icon3 {
  width: 42px;
  height: 42px;
}
.center_icon4 {
  width: 36px;
  height: 36px;
}
.center_icon5 {
  width: 38px;
  height: 44px;
}
</style>

喜欢