說(shuō)一下Animate.css這個(gè)動(dòng)畫庫(kù),很多的動(dòng)畫在這個(gè)庫(kù)里面都定義好了,我們用的時(shí)候可以直接使用里面的類名就可以了,就是直接目標(biāo)元素綁定對(duì)應(yīng)的類名就可以實(shí)現(xiàn)動(dòng)畫效果,非常方便,庫(kù)其實(shí)也相對(duì)簡(jiǎn)單,使用起來(lái)也簡(jiǎn)單。這里示例就以v3為例了,v2也是一樣的
github:https://github.com/animate-css/animate.css?
官網(wǎng):https://animate.style/?
首先安裝
pnpm add animate.css
引入?
main.js?
import 'animate.css'
使用
接下來(lái)就可以正常使用了?
注意:在添加類名的時(shí)候,里面所有的動(dòng)畫必須先設(shè)置上 animate__animated ,然后再設(shè)置對(duì)應(yīng)動(dòng)畫的類名,否則是不會(huì)生效的,大家簡(jiǎn)單看一下源碼就能了解
下面是個(gè)示例:?
?文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-675870.html
接下來(lái)代碼:?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-675870.html
<template>
<div class="main">
<label for=""><span style="fontSize: 13px;margin-right: 5px;">開啟無(wú)限輪詢</span></label>
<input v-model="isInfinite" type="checkbox">
<div class="animates-container">
<button v-for="animateName in animateNames1" :key="animateName" @click="setAnimate(animateName)">{{ animateName }}</button>
</div>
<div class="animates-container">
<button v-for="animateName in animateNames2" :key="animateName" @click="setAnimate(animateName)">{{ animateName }}</button>
</div>
<div class="animates-container">
<button v-for="animateName in animateNames3" :key="animateName" @click="setAnimate(animateName)">{{ animateName }}</button>
</div>
<div class="animates-container">
<button v-for="animateName in animateNames4" :key="animateName" @click="setAnimate(animateName)">{{ animateName }}</button>
</div>
<div class="animates-container">
<button v-for="animateName in animateNames5" :key="animateName" @click="setAnimate(animateName)">{{ animateName }}</button>
</div>
<div class="animates-container">
<button v-for="animateName in animateNames6" :key="animateName" @click="setAnimate(animateName)">{{ animateName }}</button>
</div>
<div class="animates-container">
<button v-for="animateName in animateNames7" :key="animateName" @click="setAnimate(animateName)">{{ animateName }}</button>
</div>
<div class="animates-container">
<button v-for="animateName in animateNames8" :key="animateName" @click="setAnimate(animateName)">{{ animateName }}</button>
</div>
<div class="animates-container">
<button v-for="animateName in animateNames9" :key="animateName" @click="setAnimate(animateName)">{{ animateName }}</button>
</div>
<div class="animates-container">
<button v-for="animateName in animateNames10" :key="animateName" @click="setAnimate(animateName)">{{ animateName }}</button>
</div>
<div class="testAnimate" :class="[`${animationsClass()}`, { 'animate__infinite': isInfinite }]"></div>
</div>
</template>
<script setup>
import { ref } from 'vue'
let animateNames1 = [
'bounce',
'flash',
'pulse',
'rubberBand',
'shakeX',
'shakeY',
'headShake',
'swing',
'tada',
'wobble',
'jello',
'heartBeat',
]
let animateNames2 = [
'backInDown',
'backInLeft',
'backInRight',
'backInUp',
'backOutDown',
'backOutLeft',
'backOutRight',
'backOutUp'
]
let animateNames3 = [
'bounceIn',
'bounceInDown',
'bounceInLeft',
'bounceInRight',
'bounceInUp',
'bounceOut',
'bounceOutDown',
'bounceOutLeft',
'bounceOutRight',
'bounceOutUp',
]
let animateNames4 = [
'fadeIn',
'fadeInDown',
'fadeInDownBig',
'fadeInLeft',
'fadeInLeftBig',
'fadeInRight',
'fadeInRightBig',
'fadeInUp',
'fadeInUpBig',
'fadeInTopLeft',
'fadeInTopRight',
'fadeInBottomLeft',
'fadeInBottomRight',
'fadeOut',
'fadeOutDown',
'fadeOutDownBig',
'fadeOutLeft',
'fadeOutLeftBig',
'fadeOutRight',
'fadeOutRightBig',
'fadeOutUp',
'fadeOutUpBig',
'fadeOutTopLeft',
'fadeOutTopRight',
'fadeOutBottomRight',
'fadeOutBottomLeft'
]
let animateNames5 = ref([
'flip',
'flipInX',
'flipInY',
'flipOutX',
'flipOutY'
])
let animateNames6 = ref([
'lightSpeedInRight',
'lightSpeedInLeft',
'lightSpeedOutRight',
'lightSpeedOutLeft'
])
let animateNames7 = ref([
'rotateIn',
'rotateInDownLeft',
'rotateInDownRight',
'rotateInUpLeft',
'rotateInUpRight',
'rotateOut',
'rotateOutDownLeft',
'rotateOutDownRight',
'rotateOutUpLeft',
'rotateOutUpRight'
])
let animateNames8 = ref([
'hinge',
'jackInTheBox',
'rollIn',
'rollOut'
])
let animateNames9 = ref([
'zoomIn',
'zoomInDown',
'zoomInLeft',
'zoomInRight',
'zoomInUp',
'zoomOut',
'zoomOutDown',
'zoomOutLeft',
'zoomOutRight',
'zoomOutUp'
])
let animateNames10 = ref([
'slideInDown',
'slideInLeft',
'slideInRight',
'slideInUp',
'slideOutDown',
'slideOutLeft',
'slideOutRight',
'slideOutUp'
])
let animates = ref([])
let isInfinite = ref(false)
const setAnimate = animateName => {
animates.value.shift()
animates.value.push(animateName)
}
const animationsClass = () => {
if (animates.value.length) {
return `animate__animated animate__${animates.value[0]}`
}
return ''
}
</script>
<style scoped>
.main {
width: 100%;
height: 100%;
padding: 40px 0 0 50px;
box-sizing: border-box;
overflow: hidden;
}
.main button {
margin-right: 8px;
cursor: pointer;
}
.animates-container {
margin: 20px 0;
}
.main .testAnimate {
width: 300px;
height: 300px;
background-color: red;
margin: 50px 0 0 10px;
padding: 30px;
box-sizing: border-box;
}
</style>
到了這里,關(guān)于Vue使用Animate.css的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!