15.在vue使用Animate.css庫,如何同時使用過渡和動畫

1.自定義的keyframes動畫

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue中動畫</title>
    <script src="./vue.js"> </script>
    <style>
        @keyframes bounce-in{
            0%{
                transform: scale(0)
            }
            50%{
                transform: scale(1.5)
            }
            100%{
                transform: scale(1)
            }
        }


        /* 動畫開始時存在,動畫結(jié)束時移除,監(jiān)聽到這種變化之后,就開始動畫了 默認是v-enter-active*/
        .fade-enter-active{
            transform-origin: left center;
            animation: bounce-in 1s;
            
        }
           
        /* 動畫開始時存在,動畫結(jié)束時移除,監(jiān)聽到這種變化之后,就開始動畫了 默認是.v-leave-active*/
        .fade-leave-active{
            transform-origin: left center;
            animation: bounce-in 1s reverse;
        }

    </style>
</head>
<body>


   <div id="root">
       <transition name="fade">
            <!-- <div v-show="show">hello</div> 效果相同,動態(tài)組件也帶這個動態(tài)效果-->
            <div v-if="show">hello</div>
       </transition>  
       <button @click="handleClick">切換</button>

 
   </div>

   <script>  

       Vue.component('child-one',{
          
           template:'<div>child-one</div> '
        })
 
       var app = new Vue({
           el:'#root',
           data:{
            show :true
           },
           methods:{
            handleClick:function(){
                this.show = !this.show

            }
           }

       })

   </script>

</body>

</html>
  1. 自定義動畫的名稱
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue中動畫</title>
    <script src="./vue.js"> </script>
    <style>
        @keyframes bounce-in{
            0%{
                transform: scale(0)
            }
            50%{
                transform: scale(1.5)
            }
            100%{
                transform: scale(1)
            }
        }


        /* 動畫開始時存在,動畫結(jié)束時移除,監(jiān)聽到這種變化之后,就開始動畫了 默認是v-enter-active*/
        .acive{
            transform-origin: left center;
            animation: bounce-in 1s;
            
        }
           
        /* 動畫開始時存在,動畫結(jié)束時移除,監(jiān)聽到這種變化之后,就開始動畫了 默認是.v-leave-active*/
        .leave{
            transform-origin: left center;
            animation: bounce-in 1s reverse;
        }

    </style>
</head>
<body>

<!-- 自定義動畫名稱 -->
   <div id="root">
       <transition name="fade"
                   enter-active-class="acive"
                   leave-active-class="leave"
       > 
            <!-- <div v-show="show">hello</div> 效果相同,動態(tài)組件也帶這個動態(tài)效果-->
            <div v-if="show">hello</div>
       </transition>  
       <button @click="handleClick">切換</button>

 
   </div>

   <script>  

       Vue.component('child-one',{
          
           template:'<div>child-one</div> '
        })
 
       var app = new Vue({
           el:'#root',
           data:{
            show :true
           },
           methods:{
            handleClick:function(){
                this.show = !this.show

            }
           }

       })

   </script>

</body>

</html>

3.vue使用Animate.css庫

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue中動畫</title>
    <script src="./vue.js"> </script>
    <link rel="stylesheet" type="text/css" href="./animate.css">

</head>
<body>

<!-- 自定義動畫名稱 -->
   <div id="root">
       <transition name="fade"
                   enter-active-class="animated swing"
                   leave-active-class="animated shake"
       > 
            <!-- <div v-show="show">hello</div> 效果相同,動態(tài)組件也帶這個動態(tài)效果-->
            <div v-if="show">hello</div>
       </transition>  
       <button @click="handleClick">切換</button>

 
   </div>

   <script>  

       Vue.component('child-one',{
          
           template:'<div>child-one</div> '
        })
 
       var app = new Vue({
           el:'#root',
           data:{
            show :true
           },
           methods:{
            handleClick:function(){
                this.show = !this.show

            }
           }

       })

   </script>

</body>

</html>
  1. 第一次顯示也有動畫 appear appear-active-class
   <div id="root">
       <transition name="fade"
                   appear   
                   enter-active-class="animated swing"
                   leave-active-class="animated shake"
                   appear-active-class="animated slideInDown"
                   > 
            <div v-if="show">hello</div>
       </transition>  
       <button @click="handleClick">切換</button>
  1. 入場動畫css3+過渡動畫效果
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue中動畫</title>
    <script src="./vue.js"> </script>
    <link rel="stylesheet" type="text/css" href="./animate.css">
    <style>
        .fade-enter,.fade-leave-to{
            opacity: 0;
        }
        .fade-enter-active,.fade-leave-active{
            transition: opacity 3s;
        }
    </style>
</head>
<body>

        <!-- 入場動畫css3+過渡動畫效果-->
        <!-- type="transition"以transition動畫時長為標準 -->
        <!-- :duration='10000'自定義動畫時長,10000是10秒 -->
   <div id="root">
       <transition type="transition"
                   :duration="{enter:5000,leave:10000}"
                   name="fade"
                   appear   
                   enter-active-class="animated swing fade-enter-active"
                   leave-active-class="animated shake fade-leave-active"
                   appear-active-class="animated slideInDown"
                   > 
            <div v-if="show">hello</div>
       </transition>  
       <button @click="handleClick">切換</button>

 
   </div>

   <script>  

       Vue.component('child-one',{
          
           template:'<div>child-one</div> '
        })
 
       var app = new Vue({
           el:'#root',
           data:{
            show :true
           },
           methods:{
            handleClick:function(){
                this.show = !this.show

            }
           }

       })

   </script>

</body>

</html>

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

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

  • 在iOS中隨處都可以看到絢麗的動畫效果,實現(xiàn)這些動畫的過程并不復雜,今天將帶大家一窺iOS動畫全貌。在這里你可以看...
    F麥子閱讀 5,273評論 5 13
  • 1 周曉宇有意識的時候,他正騎著烏騅馬不斷的奔騰,只見烏騅通體烏黑發(fā)亮,四個蹄子雪白如雪,健步如飛,身輕如燕。再看...
    輝的閱讀 809評論 5 36
  • 最近在清理電腦磁盤,翻出好多以前的東西。最多的就是手機拍的照片和視頻。 不論美丑。 還有就是一些軟件包。 大二的時...
    敬千帆閱讀 246評論 0 1

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