Newer
Older
HuangJiPC / src / pages / views / prevention / index.vue
@zhangdeliang zhangdeliang on 21 Jun 2 KB update
<template>
  <div class="container">
    <div
      class="showAndHidden"
      ref="showAndHiddenRef"
      :class="show ? 'Button1' : 'Button2'"
      @click="showBox()"
    >
      显示/隐藏
    </div>
    <transition name="left">
      <PreventionLeft v-show="show"></PreventionLeft>
    </transition>
    <PreventionMap></PreventionMap>
    <transition name="right">
      <PreventionRight v-show="show"></PreventionRight>
    </transition>
  </div>
</template>

<script>
import { reactive, toRefs, ref } from "vue";

import PreventionLeft from "./preventionLeft.vue";
import PreventionMap from "./preventionMap.vue";
import PreventionRight from "./preventionRight.vue";
export default {
  name: "prevention",
  components: {
    PreventionLeft,
    PreventionMap,
    PreventionRight,
  },
  setup() {
    const state = reactive({
      show: true,
    });
    const showBox = () => {
      state.show = !state.show;
    };
    return {
      ...toRefs(state),
      showBox,
    };
  },
};
</script>

<style lang='less' scoped>
.container {
  width: 100%;
  height: 100%;
  position: relative;

  .showAndHidden {
    position: absolute;
    left: 436px;
    top: 0px;
    width: 100px;
    height: 30px;
    text-align: center;
    line-height: 30px;
    background: yellowgreen;
    z-index: 10;
    cursor: pointer;
  }
  .Button1 {
    left: 436px;
    animation: Button1 0.6s linear;
  }
  .Button2 {
    left: 10px;
    animation: Button2 0.6s linear;
  }
}
.right-enter-active {
  animation: test2 0.6s linear;
}
.right-leave-active {
  animation: test2 0.6s linear reverse;
}
.left-enter-active {
  animation: test1 0.6s linear;
}
.left-leave-active {
  animation: test1 0.6s linear reverse;
}
// 按钮
@keyframes Button1 {
  0% {
    left: 10px;
  }
  100% {
    left: 436px;
  }
}
@keyframes Button2 {
  0% {
    left: 436px;
  }
  100% {
    left: 10px;
  }
}
// 左边
@keyframes test1 {
  0% {
    left: -400px;
    opacity: 0;
  }
  100% {
    left: 0;
    opacity: 1;
  }
}
// 右边
@keyframes test2 {
  0% {
    right: -400px;
    opacity: 0;
  }
  100% {
    right: 0;
    opacity: 1;
  }
}
</style>