vue封装Animate.css动画库的使用

今天给大家分享一下Animate这个动画库的封装使用

目录

引入Animate.css

封装方法

 使用

引入Animate.css

npm i animate.css --save

在main.js入口文件里引入

import 'animate.css';

封装方法

/**
 * 
 * @param {*} element 传入的H5元素对象
 * @param {*} animation 动画名称
 * @param {*} prefix 可以不用传,默认参数即可
 * @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();
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值