vue+ts或者react+ts如何使用animate.css

简介: vue+ts或者react+ts如何使用animate.css


前言

animate.css是一个第三方的纯css库,其中内置了众多我们常用的动画特效,详细特效及文档可以浏览animate.style以及animate.css动画演示,关于源码,可查看animate.css源码

使用animate.css(以vue+ts为例,react可参照类似方法)

  1. 安装
npm i animate.css -S
  1. main.ts中引入
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import animated from 'animate.css'; // 引入animate.css
const app = createApp(App);
app.use(store);
app.use(router);
app.use(animated); // 注册animate.css
app.mount('#app');
window.vm = app;
  1. 此时会提示找不到模块“animate.css”或其相应的类型声明

    那么我们就需要修改shims-vue.d.ts,声明一下animate.css的类型
/* eslint-disable */
declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default component
}
declare module '*.vue' {
  import Vue from 'vue';
  export default Vue;
}
declare module '*.png' {
  export const png: any;
}
declare module '*.jpg' {
  export const jpg: any;
}
declare module '*.jpeg' {
  export const jpeg: any;
}
declare module '*.gif' {
  export const gif: any;
}
declare module 'animate.css' // 声明animate.css的类型,否则引入animate.css会报错,提示找不到animate.css模块
declare global {
  interface Window {
    [propName: string]: any;
  }
}
  1. 组件中使用animate.css,需要注意的是,样式class类名,必须加上animate__animated,其次则是要引入动画的class类名,如animate__slideInUp
<template>
  <div class="content-box animate__animated animate__slideInUp">
    滑动进入特效演示
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
  setup() {},
});
</script>
<style lang="scss" scoped>
.content-box {
  width: 200px;
  height: 200px
}
</style>
  1. 如果想修改动画的属性,比如执行时间,延迟等等,有以下几种方法
    ①方法1:直接通过动画class类名animated修改
.animated {
    -webkit-animation-duration: 1s; 
    animation-duration: 2s; // 动画执行时间
    -webkit-animation-fill-mode: both;
    animation-fill-mode: both;
}
  1. ②方法2:修改指定动画的属性
.animate__slideInUp {
    -webkit-animation-duration: 1s; 
    animation-duration: 2s; // 动画执行时间
    -webkit-animation-fill-mode: both;
    animation-fill-mode: both;
}
  1. ③方法3:在要执行动画的div设置stye
<div class="content-box animate__animated animate__slideInUp" :style="{animationDuration: '500ms'}"></div>
目录
相关文章
|
JSON 前端开发 JavaScript
CSS模块postcss-modules,在jsx中实现vue里的scoped
CSS模块postcss-modules,在jsx中实现vue里的scoped
498 1
|
前端开发
React使用useRef ts 报错
【8月更文挑战第17天】
427 4
|
前端开发
create-react-app 如何使用 less/sass 和 react-css-modules?
本文详细介绍了在 create-react-app 项目中如何使用 less/sass 和 react-css-modules 来管理和应用样式。首先,通过安装相应依赖并配置 webpack 支持 less/sass;接着,介绍如何使用这些预处理器编写样式;最后,讲解了如何配置和使用 react-css-modules 实现样式的模块化管理,以及如何结合使用 less/sass 和 react-css-modules 提高开发效率和代码质量。
587 3
|
前端开发 JavaScript
React Tailwind CSS
10月更文挑战第12天
714 1
|
资源调度 JavaScript 前端开发
使用vite+react+ts+Ant Design开发后台管理项目(二)
使用vite+react+ts+Ant Design开发后台管理项目(二)
|
前端开发 C++
使用 Vite 创建 React+TS+SW 项目并整合 AntDesign 、Scss 等组件或插件
本文记录了如何使用Vite创建一个React+TypeScript+Service Workers(SW)项目,并整合AntDesign组件库和Scss等插件,包括项目的创建、配置问题解决、AntDesign和Scss的整合方法。
1410 1
|
前端开发 JavaScript
使用Vue+CSS实现汉堡图标过渡为叉号图标,有点意思
本文分享了如何使用Vue和CSS实现一个汉堡图标在点击时过渡为叉号图标的动画效果,并提供了详细的实现代码和效果演示。
374 0
使用Vue+CSS实现汉堡图标过渡为叉号图标,有点意思
|
前端开发 容器
React 使用 CSS 样式
10月更文挑战第12天
326 0
|
JavaScript 前端开发 容器
vue组件封装——固定宽高比的容器(2种方法:纯CSS实现 + JS实现)
vue组件封装——固定宽高比的容器(2种方法:纯CSS实现 + JS实现)
644 2
|
JavaScript 前端开发
vue 模拟随机变速的动态打字特效【支持多行文本】(含css实现闪烁光标,js动态改变setInterval定时器的时间间隔)
vue 模拟随机变速的动态打字特效【支持多行文本】(含css实现闪烁光标,js动态改变setInterval定时器的时间间隔)
346 1