Vue中使用animate.css库
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Vue中使用animate.css库</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <link rel="stylesheet" type="text/css" href="css/animate.css" /> <style type="text/css"> @keyframes bounce-in { 0% { transform: scale(0); } 50% { transform: scale(1.5); } 100% { transform: scale(1); } } .fade-enter-active { transform-origin: left center; animation: bounce-in 1s; } .fade-leave-active { transform-origin: left center; animation: bounce-in 1s reverse; } .active { transform-origin: left center; animation: bounce-in 1s; } .leave { transform-origin: left center; animation: bounce-in 1s reverse; } .fade-enter, .fade-leave-to { opacity: 0; } .fade-enter-active, .fade-leave-active{ transition: opacity 3s; } </style> </head> <body> <div id="root"> <transition name="fade"> <div v-show="show">Harold</div> </transition> <!--自定义Class--> <transition name="fade" enter-active-class="active" leave-active-class="leave"> <div v-if="show">Harold</div> </transition> <button @click="handleBtnClick">change</button> <transition name="fade" enter-active-class="animated swing" leave-active-class="animated shake"> <div v-if="show">animate.css</div> </transition> <!--第一次显示的时候也有动画效果——初始动画--> <transition name="fade" appear enter-active-class="animated swing" leave-active-class="animated shake" appear-active-class="animated swing"> <div v-if="show">animate.css</div> </transition> <!--Vue中同时使用过渡和动画--> <transition name="fade" appear enter-active-class="animated swing fade-enter-active" leave-active-class="animated shake fade-leave-active" appear-active-class="animated swing"> <div v-if="show">animate.css</div> </transition> <!--Vue中同时使用过渡和动画,时长定义以transition3s的为准(animate的默认1s)--> <transition name="fade" type="transition" appear enter-active-class="animated swing fade-enter-active" leave-active-class="animated shake fade-leave-active" appear-active-class="animated swing"> <div v-if="show">animate.css</div> </transition> <!--Vue中同时使用过渡和动画,时长自定义--> <transition name="fade" :duration="5000" appear enter-active-class="animated swing fade-enter-active" leave-active-class="animated shake fade-leave-active" appear-active-class="animated swing"> <div v-if="show">animate.css</div> </transition> <transition name="fade" :duration="{enter: 5000, leave: 10000}" appear enter-active-class="animated swing fade-enter-active" leave-active-class="animated shake fade-leave-active" appear-active-class="animated swing"> <div v-if="show">animate.css</div> </transition> </div> <script type="text/javascript"> var vm = new Vue({ el: '#root', data: { show: true }, methods: { handleBtnClick() { this.show = !this.show } } }) </script> </body> </html>
略懂,略懂....