vue封裝Animate.css動畫庫的使用方式
更新時間:2024年04月29日 10:27:14 作者:Summer不禿
這篇文章主要介紹了vue封裝Animate.css動畫庫的使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
今天給大家分享一下Animate這個動畫庫的封裝使用
引入Animate.css
npm i animate.css --save
在main.js入口文件里引入
import 'animate.css';
封裝方法
/** * * @param {*} element 傳入的H5元素對象 * @param {*} animation 動畫名稱 * @param {*} prefix 可以不用傳,默認參數(shù)即可 * @returns */ export const animateCSS = (element, animation, prefix = 'animate__') => { new Promise((resolve, reject) => { const animationName = `${prefix}${animation}` element.classList.add(`${prefix}animated`, animationName) function handleAnimationEnd(event) { event.stopPropagation() element.classList.remove(`${prefix}animated`, animationName) resolve('Animation ended') } element.addEventListener('animationend', handleAnimationEnd, {once: true}) }) }
使用
import { animateCSS } from "@/utils/function"; import { onMounted, ref } from "vue"; const introTitle = ref(); const introImg = ref(); const header = ref(); console.log('撿來了'); const domAnime = () => { animateCSS(introTitle.value, "fadeInLeft"); introTitle.value.style.display = "block"; animateCSS(introImg.value, "fadeInRight"); introImg.value.style.display = "block"; animateCSS(header.value, "fadeInDown"); }; onMounted(() => { domAnime(); });
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue項目開發(fā)中setTimeout等定時器的管理問題
這篇文章主要介紹了vue項目開發(fā)中setTimeout等定時器的管理問題,需要的朋友可以參考下2018-09-09Vue3中的defineExpose函數(shù)用法深入解析
這篇文章主要介紹了Vue3中的defineExpose函數(shù)用法的相關(guān)資料,defineExpose是Vue3中用于在模式下暴露組件內(nèi)部屬性和方法的輔助函數(shù),它允許父組件通過ref訪問子組件的暴露內(nèi)容,提高組件間的交互能力并保持封裝性,需要的朋友可以參考下2025-01-01vue 解決在微信內(nèi)置瀏覽器中調(diào)用支付寶支付的情況
這篇文章主要介紹了vue 解決在微信內(nèi)置瀏覽器中調(diào)用支付寶支付的情況,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11從Echarts報錯中學(xué)習Vue3?ref和shallowRef區(qū)別及其組件二次封裝demo
這篇文章主要介紹了從Echarts報錯中學(xué)習Vue3?ref和shallowRef區(qū)別及其組件二次封裝demo,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-11-11