7.1 万 Star!超实用,60 多种动画效果的 CSS 库

开发 前端
animate.css 是一个有趣的,跨浏览器的CSS3 动画库。

简介

animate.css 是一个有趣的,跨浏览器的 css3 动画库,兼容性好,使用方便。它预设了抖动、闪烁、弹跳、翻转、旋转、淡入淡出等多达 60 多种动画效果,几乎包含了所有常见的动画效果。

animate.css 基于 CSS3,只兼容支持 CSS3 animate 属性的浏览器,IE10+、Firefox、Chrome、Opera、Safari。

项目地址是:

https:// github.com/animate-css/ animate.css

安装

  • 使用 npm 安装:
  1. $ npm install animate.css --save 
  • 使用 yarn 安装:
  1. $ yarn add animate.css 
  • 使用 CDN 直接引入:
  1. <head> 
  2.   <link 
  3.     rel="stylesheet" 
  4.     href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" 
  5.   /> 
  6. </head> 

简单使用

  • 基本用法。安装 animate.css 后,将以下属性添加到中即可完成动画效果的创建。
  1. <h1 class="animate__animated animate__bounce">An animated element</h1> 
  • 自定义属性。使用自定义属性来定义动画持续时间、延迟,这使得它非常灵活,当需要更改动画持续时间的时间,只需要为全局或本地设置一个新值。
  1. /* This only changes this particular animation duration */ 
  2. .animate__animated.animate__bounce { 
  3.   --animate-duration: 2s; 
  4.  
  5. /* This changes all the animations globally */ 
  6. :root { 
  7.   --animate-duration: 800ms; 
  8.   --animate-delay: 0.9s; 
  • 同时自定义属性还可以动态更改所有时间受限的属性,可以通过 JS 脚本动态修改。
  1. // All animations will take twice the time to accomplish 
  2. document.documentElement.style.setProperty('--animate-duration''2s'); 
  3.  
  4. // All animations will take half the time to accomplish 
  5. document.documentElement.style.setProperty('--animate-duration''.5s'); 
  • 延迟效果:可以直接在元素的 class 属性上添加延迟效果:
  1. <div class="animate__animated animate__bounce animate__delay-2s">Example</div> 
  2.  
  3. // animate.css 提供了这些延迟属性: 
  4. class               默认延迟时间 
  5. animate__delay-2s   2s 
  6. animate__delay-3s   3s 
  7. animate__delay-4s   4s 
  8. animate__delay-5s   5s 
  9.  
  10. // 也可以通过 --animate-delay 属性进行自定义: 
  11. /* All delay classes will take 2x longer to start */ 
  12. :root { 
  13.   --animate-delay: 2s; 
  14.  
  15. /* All delay classes will take half the time to start */ 
  16. :root { 
  17.   --animate-delay: 0.5s; 
  • 动画速度:可以通过添加这些 class 来控制动画的速度:
  1. <div class="animate__animated animate__bounce animate__faster">Example</div> 
  2.  
  3. // 速度的 class 包括这些: 
  4. class            默认速度 
  5. animate__slow    2s 
  6. animate__slower  3s 
  7. animate__fast    800ms 
  8. animate__faster  500ms 
  9.  
  10. // 可以通过 --animate-duration 全局或本地属性自定义动画时间: 
  11.  
  12. /* All animations will take twice as long to finish */ 
  13. :root { 
  14.   --animate-duration: 2s; 
  15.  
  16. /* Only this element will take half the time to finish */ 
  17. .my-element { 
  18.   --animate-duration: 0.5s; 
  • 循环效果:可以通过添加这些 class 来控制动画的循环次数:
  1. <div class="animate__animated animate__bounce animate__repeat-2">Example</div> 
  2.  
  3. // 可供选择的 class 有: 
  4. class              循环次数 
  5. animate__repeat-1  1 
  6. animate__repeat-2  2 
  7. animate__repeat-3  3 
  8. animate__infinite  无限循环 
  9.  
  10. // 类似的,也可以自定义循环次数: 
  11. /* The element will repeat the animation 2x 
  12.    It's better to set this property locally and not globally or 
  13.    you might end up with a messy situation */ 
  14. .my-element { 
  15.   --animate-repeat: 2

 

 

责任编辑:张燕妮 来源: 知乎
相关推荐

2021-05-11 08:30:54

前端css技术热点

2011-03-09 09:25:12

CSS3

2015-03-23 17:43:31

transitionViewControl

2020-02-27 09:46:19

GitHub代码开发者

2011-06-29 13:22:58

CSS3

2023-11-01 08:33:45

CSS动画效果

2018-12-12 19:10:01

Oracle数据库自动备份

2022-06-23 09:04:14

ReactHooks项目

2022-06-29 21:22:49

CSS动感倒计时

2012-12-26 10:34:56

CSSWeb前端

2024-03-28 09:11:24

CSS3TransitionCSS属性

2017-02-06 13:00:49

Android翻转卡片动画效果

2009-09-22 12:59:58

ibmdwDojo

2011-07-08 10:15:15

IPhone 动画

2021-01-25 16:23:15

5G基站网络

2015-12-01 09:52:03

CSS3动画源码

2023-08-29 07:52:09

CSS库网络动画

2023-04-18 10:03:51

AI英伟达

2019-03-06 14:06:26

MySQL数据库乱码

2021-04-14 15:15:46

开源技术 工具
点赞
收藏

51CTO技术栈公众号