1. 程式人生 > 其它 >Vue 結合 Animate.CSS 實現簡單動畫效果

Vue 結合 Animate.CSS 實現簡單動畫效果

我們在做專案的時候,對於一些頁面元素如果能新增一些動畫效果,那肯定是非常 炫酷 的,今天介紹一個第三方動畫庫 —— Animate.css .

用法很簡單,不過新手容易踩坑。注意,前提是你的 計算機 高階系統設定裡,效能選項裡 選擇 “調整為最佳外觀” 即可。

一、在 <head> </head> 中引入 Animate.CSS :

<head>
<link
  rel="stylesheet"
  href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
/>
</head>

二、HTML 部分:

<div id="example-1">
  <button @click="show = !show">Toogle</button>
  
  <transition
    enter-active-class="animate__animated animate__backInDown"
    leave-active-class="animate__animated animate__bounceOutDown"
  >
    <div v-show="show">
      Hello
    
</div> </transition> </div>

三、Script 部分:

var app = new Vue({
  el: '#example-1',
  data: {
    show: true,
  }
})

此時,動畫效果已經可以展示啦: