vue2使用transition過(guò)渡動(dòng)畫(huà),初始動(dòng)畫(huà)無(wú)效果

v2中使用默認(rèn)的xx-enter-fromxx-leave-to的css不生效,導(dǎo)致初始動(dòng)畫(huà)無(wú)效
解決辦法:使用animation自定義過(guò)渡動(dòng)畫(huà)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      p {
        width: 200px;
        height: 100px;
        background: red;
        position: absolute;
        right: 20px;
        overflow: hidden;
      }
      .slide-fade-enter-active {
        animation: bounce-in 5s ease;
      }
      .slide-fade-leave-active {
        animation: bounce-in 5s reverse;
      }

      @keyframes bounce-in {
        0% {
          width: 0;
        }
        100% {
          width: 200px;
        }
      }
    </style>
  </head>
  <body>
    <div id="app">test</div>
  </body>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
  <script>
    new Vue({
      template: `<div><button @click="show = !show">Toggle Slide + Fade</button>
  <Transition appear name="slide-fade" mode="in-out">
    <p v-if="show">hello</p>
  </Transition></div>`,
      data() {
        return {
          show: false
        }
      }
    }).$mount('#app')
  </script>
</html>

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

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

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