【CSS】使用transition實(shí)現(xiàn)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>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容