【CSS】使用transition实现div面板的过渡动画

动画.gif
<template>
  <div class="box">
    <div class="button" @click="clickBtn">
      <img src="./img/left.png" alt="" v-show="!show" />
      <img src="./img/right.png" alt="" v-show="show" />
    </div>
    <div class="content">
      <div>
        <div>111111111111111111111111111111111</div>
        <div>2222222222222222222</div>
        <div>333333333333333333333333</div>
        <div>444444444444</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";

const show = ref(false);

const clickBtn = () => {
  let div = document.getElementsByClassName("content")[0];
  div.classList.toggle("content_show");
  show.value = !show.value;
};
</script>

<style lang="less">
.box {
  display: flex;
  justify-content: end;
  position: absolute;
  right: 50px;
  overflow: hidden;
}
.content {
  width: 0px;
  height: 300px;
  background: skyblue;
  transition: all 0.5s ease;
}
.content_show {
  width: 500px;
  height: 300px;
  background: skyblue;
}
.button {
  width: 50px;
  height: 50px;
  background: coral;
  img {
    width: 50px;
    height: 50px;
  }
}
</style>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容