手机菜单栏三条杠

15 篇文章 0 订阅
这是一个使用Vue.js实现的侧边栏菜单组件,包含登录按钮和免费体验按钮。点击菜单按钮会切换侧边栏的显示状态,通过CSS过渡效果实现平滑的动画。侧边栏显示时,有一个半透明的灰色背景,并且中间的线条会旋转成一个角度,形成一个关闭的图标。
摘要由CSDN通过智能技术生成
<template>
  <div class="body">
    <div class="nar-bar">
      <div class="menu" @click="menuClick()">
        <div :class="{ middleline: true, menulineactive: sidebarIsShow }">
          <!--<div class="middleline"></div>-->
        </div>
        <p v-if="menuIsShow">MENU</p>
        <p v-if="closeIsShow">CLOSE</p>
      </div>
      <transition name="sidebartransition"> //transition标签

        <div class="sidebarbgc" v-if="sidebarIsShow">
          <div :class="{ graybgc: true, graybgcactive: sidebarIsShow }"></div>
          //外层的半透明灰色背景
          <div class="sidebarwhite">
            <div class="mbloginbefore" v-if="!isLoginFn">
              <!--//与本例无关的一些占位内容↓↓↓-->
              <div class="mblogin">
                <button @click="gotoLogin()">LOGIN</button>
              </div>
              <div class="freeexp">
                <button>無料体験会 / 体験予約</button>
              </div>
            </div>
          </div>
        </div>
      </transition>
    </div>
    <router-view></router-view>
    <bottom></bottom>
  </div>
</template>
<script>
  import bottom from '@/components/bottom'

  export default {
    data() {
      return {
        sidebarIsShow: false
      }
    },
    methods: {
      gotoLogin() {
      },
      menuClick() {
        this.sidebarIsShow = !this.sidebarIsShow
      }
    },
    components: {
      bottom
    }
  }
</script>
<style lang="scss" scoped>
  .body {
    width: 100%;
    .nar-bar {
      margin: 0 auto;
      width: 100%;
      background: #ffed00;
      height: 2rem;
      line-height: 2rem;
    }

    .logo {
      width: 64px;
    }
    .sidebarbgc {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }

    .sidebartransition {
      &-enter {
        transform: translateX(-100%); //整体划入之前隐藏在最左侧
      }
      &-enter-active {
        transition: all 0.5s ease; //划入过渡,用时0.5s
      }
      &-leave-to {
        transform: translateX(-120%); //整体划出之后隐藏在最左侧,之所以设置为-120%,见后文
      }
      &-leave-active {
        transition: all 0.5s ease; //划出过渡,用时0.5s
      }
    }
    .graybgc {
      position: absolute;
      width: 100%;
      height: 100%;
      z-index: -1;
      background-color: rgba($color: #000000, $alpha: 0.5);
    }
    .graybgcactive {
      width: 120%; //当侧边栏显示时,即sidebarIsShow为true时,灰色滑块变动宽度为120%
    }
    .middleline {
      z-index: 3;
      display: inline-block;
      line-height: 65px;
      width: 55px;
      height: 5px;
      border-radius: 3px;
      background-color: #ffffff;
      position: relative;
      transition: all 0.5s ease;
      &::before { //前一条线
        content: "";
        position: absolute;
        width: 55px;
        height: 5px;
        bottom: 17px;
        border-radius: 3px;
        background-color: #ffffff;
        transition: all 0.5s ease;
      }
      &::after { //后一条线
        content: "";
        position: absolute;
        width: 55px;
        height: 6px;
        top: 17px;
        border-radius: 3px;
        background-color: #ffffff;
        transition: all 0.5s ease;
      }
    }
    .menulineactive {
      display: inline-block;
      z-index: 3;
      line-height: 65px;
      width: 55px;
      height: 5px;
      border-radius: 3px;
      background-color: #ffffff;
      position: relative;
      transform: rotate(45deg); //中间的线顺时针旋转45°

      &::before {
        content: "";
        position: absolute;
        width: 55px;
        height: 5px;
        bottom: 0px;
        border-radius: 3px;
        background-color: #ffffff;
        transform: rotate(-90deg); //上方的线逆时针旋转90°
        transition: all 0.5s ease;
      }
      &::after {
        opacity: 0; //底部的线隐藏
      }
    }
  }

</style>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值