vue中使用animate.css實(shí)現(xiàn)炫酷動(dòng)畫效果
animate.css 是一個(gè)來自國外的 CSS3 動(dòng)畫庫,它提供了抖動(dòng)(shake)、閃爍(flash)、彈跳(bounce)、翻轉(zhuǎn)(flip)、旋轉(zhuǎn)(rotateIn/rotateOut)、淡入淡出(fadeIn/fadeOut)等多達(dá) 60 多種動(dòng)畫效果,幾乎包含了所有常見的動(dòng)畫效果。這些效果在大多數(shù)支持CSS3的瀏覽器上都能保持一致。簡單來說,我們使用它,只需要寫很少的代碼,就可以實(shí)現(xiàn)非常炫酷的動(dòng)畫效果。
官網(wǎng): https://animate.style/
1.安裝(在vscode終端中,使用npm安裝)
npm install animate.css
2.引入
在Test.vue中引入
import 'animate.css'
3.代碼實(shí)現(xiàn)
Test.vue文件如下:
<template> <div> <button @click="isShow = !isShow">顯示/隱藏</button> <!-- appear:一上來就有動(dòng)畫效果 enter-active-class:設(shè)置進(jìn)入的動(dòng)畫 leave-active-class:設(shè)置離開的動(dòng)畫 --> <!-- <transition appear name="animate__animated animate__bounce" enter-active-class="animate__slideInUp" leave-active-class="animate__zoomOut" > <h2 v-show="isShow">animate.css!</h2> </transition> --> <transition-group appear name="animate__animated animate__bounce" enter-active-class="animate__swing" leave-active-class="animate__backOutUp" > <h2 v-show="!isShow" key="1">你好啊!</h2> <!--一定要設(shè)置key--> <h2 v-show="isShow" key="2">animate.css!</h2> </transition-group> </div> </template> <script> import 'animate.css' export default { name:'Test3', data(){ return { isShow:true } } } </script> <style scoped> h2{ background-color: skyblue; } </style>
在App.vue中注冊(cè)、使用Test.vue即可
<template> <div> <Test/> </div> </template> <script> import Test from './components/Test' export default { name:'App', components:{Test} } </script> <style> </style>
注意:
- 要想使用animate.css, 需要把相關(guān)標(biāo)簽用
<transition>.....</transition>
進(jìn)行包裹,只能包裹單個(gè)標(biāo)簽。 - 使用
<transition-group>.....</transition-group>
可以包裹多個(gè)標(biāo)簽,注意一定要加key
這個(gè)屬性值 - appear :表示一上來就有動(dòng)畫效果。相當(dāng)于:
:appear = 'true'
- 自定義修改
進(jìn)入、離開的動(dòng)畫可以從官網(wǎng)中選擇自己喜歡的,點(diǎn)擊上圖中紅線框標(biāo)識(shí)進(jìn)行復(fù)制,直接替換掉下圖中紅線框內(nèi)容即可。
5、使用:duration
設(shè)置動(dòng)畫統(tǒng)一的運(yùn)行時(shí)長,單位:ms
<!-- 設(shè)置入場和離場的運(yùn)行時(shí)長都是一樣的 時(shí)間單位:ms <transition :duration="1000">...</transition> --> <transition appear name="animate__animated animate__bounce" enter-active-class="animate__slideInUp" leave-active-class="animate__zoomOut" :duration="1000" > <h2 v-show="isShow">animate.css!</h2> </transition> <!-- 分開設(shè)置入場`enter`和離場`leave`的運(yùn)行時(shí)長。 <transition :duration="{ enter: 500, leave: 800 }">...</transition> --> <transition appear name="animate__animated animate__bounce" enter-active-class="animate__slideInUp" leave-active-class="animate__zoomOut" :duration="{ enter:200, leave:1500 }" > <h2 v-show="isShow">animate.css!</h2> </transition>
到此這篇關(guān)于vue中使用animate.css實(shí)現(xiàn)動(dòng)畫效果的文章就介紹到這了,更多相關(guān)vue使用animate.css動(dòng)畫效果內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue-pdf實(shí)現(xiàn)文件在線預(yù)覽
這篇文章主要為大家詳細(xì)介紹了vue-pdf實(shí)現(xiàn)文件在線預(yù)覽,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08vue 做移動(dòng)端微信公眾號(hào)采坑經(jīng)驗(yàn)記錄
這篇文章主要介紹了vue 做移動(dòng)端微信公眾號(hào)采坑經(jīng)驗(yàn)記錄,文中是小編記錄的三個(gè)坑及解決方案,需要的朋友可以參考下2018-04-04vue父組件向子組件(props)傳遞數(shù)據(jù)的方法
這篇文章主要介紹了vue父組件向子組件(props)傳遞數(shù)據(jù)的方法,文中給大家補(bǔ)充介紹了vue父子組件間傳值(props)的實(shí)現(xiàn)代碼,需要的朋友可以參考下2018-01-01Vue3封裝ElImageViewer預(yù)覽圖片的示例代碼
本文主要介紹了Vue3封裝ElImageViewer預(yù)覽圖片的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07vue+elementUI組件遞歸實(shí)現(xiàn)可折疊動(dòng)態(tài)渲染多級(jí)側(cè)邊欄導(dǎo)航
這篇文章主要介紹了vue+elementUI組件遞歸實(shí)現(xiàn)可折疊動(dòng)態(tài)渲染多級(jí)側(cè)邊欄導(dǎo)航,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04vue3+ts+Vuex中使用websocket協(xié)議方式
這篇文章主要介紹了vue3+ts+Vuex中使用websocket協(xié)議方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10vue+vue-meta-info動(dòng)態(tài)設(shè)置meta標(biāo)簽教程
這篇文章主要介紹了vue+vue-meta-info動(dòng)態(tài)設(shè)置meta標(biāo)簽教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04