css实现导航栏切换动画

 

先来看看效果

 

一个简单的效果实现,本例使用vue实现:

<template>
  <div class="menu" :class="{ 'menu-select': isMenu }" @click="setMenu"></div>
</template>

 

<script>
import { reactive, toRefs } from "@vue/composition-api";
export default {
  setup(props, content) {
    const data = reactive({
      isMenu: false,
    });

    const setMenu = () => {
      data.isMenu = !data.isMenu;
    };

    return {
      ...toRefs(data),
      setMenu,
    };
  },
};
</script>

 

<style lang="scss">
.menu {
  width: 40px;
  height: 40px;
  position: relative;
  cursor: pointer;
}
.menu:before,
.menu:after {
  content: "";
  display: block;
  width: 40px;
  height: 6px;
  background: #00ffff;
  border-radius: 3px;
  position: absolute;
  left: 0;
  -webkit-transition: all 0.15s ease-in-out;
  transition: all 0.15s ease-in-out;
}
.menu:before {
  top: 5px;
  box-shadow: 0 30px #00ffff;
}
.menu:after {
  bottom: 15px;
}
.menu-select:before {
  top: 17px;
  box-shadow: none;
  -webkit-transform: rotate(225deg);
  transform: rotate(225deg);
}
.menu-select:after {
  bottom: 17px;
  -webkit-transform: rotate(135deg);
  transform: rotate(135deg);
}
</style>

 

说明:js只是辅助,css才是重点。

posted @ 2021-08-04 14:07  我若亦如风  阅读(588)  评论(0编辑  收藏  举报