animate.css的使用

animate.css的使用[1]引入[2]效果演示[3]实际应用

大家好,又见面了,我是你们的朋友全栈君。

前面的话

  animate.css是一个使用CSS3的animation制作的动画效果的CSS集合,里面预设了很多种常用的动画,且使用非常简单。本文将详细介绍animate.css的使用

 

引入

  animate.css的最新版本是3.5.2,引入animate.css很容易,有以下几种方法

  1、从官网下载

  https://raw.github.com/daneden/animate.css/master/animate.css

  2、通过npm安装

$ npm install animate.css

  3、使用在线cdn

https://unpkg.com/animate.css@3.5.2/animate.min.css

 

效果演示

  animate.css的使用非常简单,因为它是把不同的动画绑定到了不同的类里,所以想要使用哪种动画,只需要把通用类animated和相应的类添加到元素上就行了

  下面来详细介绍animate.css里面的类,主要包括Attention(晃动效果)、bounce(弹性缓冲效果)、fade(透明度变化效果)、flip(翻转效果)、rotate(旋转效果)、slide(滑动效果)、zoom(变焦效果)、special(特殊效果)这8类

【Attention(晃动效果)】

bounce
flash
pulse
rubberBand
shake
headShake
swing
tada
wobble
jello

  以在div上使用bounce为例

<div class="animated bounce"></div>

【bounce(弹性缓冲效果)】

bounceIn
bounceInDown
bounceInLeft
bounceInRight
bounceInUp
bounceOut
bounceOutDown
bounceOutLeft
bounceOutRight
bounceOutUp

【fade(透明度变化效果)】

fadeIn
fadeInDown
fadeInDownBig
fadeInLeft
fadeInLeftBig
fadeInRight
fadeInRightBig
fadeInUp
fadeInUpBig
fadeOut
fadeOutDown
fadeOutDownBig
fadeOutLeft
fadeOutLeftBig
fadeOutRight
fadeOutRightBig
fadeOutUp
fadeOutUpBig

【flip(翻转效果)】

flip
flipInX
flipInY
flipOutX
flipOutY

【rotate(旋转效果)】 

rotateIn
rotateInDownLeft
rotateInDownRight
rotateInUpLeft
rotateInUpRight
rotateOut
rotateOutDownLeft
rotateOutDownRight
rotateOutUpLeft
rotateOutUpRight

【slide(滑动效果)】 

slideInDown
slideInLeft
slideInRight
slideInUp
slideOutDown
slideOutLeft
slideOutRight
slideOutUp

【zoom(变焦效果)】

zoomIn
zoomInDown
zoomInLeft
zoomInRight
zoomInUp
zoomOut
zoomOutDown
zoomOutLeft
zoomOutRight
zoomOutUp

【special(特殊效果)】 

hinge
rollIn
rollOut
lightSpeedIn
lightSpeedOut

 

实际应用

  在一般的使用中,直接在元素上添加animated和对应的类名即可

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://unpkg.com/animate.css@3.5.2/animate.min.css">
<style>
.box{height: 100px;width: 100px;background-color: lightblue}
</style>
</head>
<body>
<div class="box animated flash"></div>
</body>
</html>
<span role="heading" aria-level="2">animate.css的使用

  通过给JS添加或删除class,可以实现动态效果

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://unpkg.com/animate.css@3.5.2/animate.min.css">
<style>
.box{height: 100px;width: 100px;background-color: lightblue}
</style>
</head>
<body>
<button id="btn1">添加</button>
<button id="btn2">移除</button>
<div id="box" class="box"></div>
<script>
var oBtn1 = document.getElementById('btn1');
var oBtn2 = document.getElementById('btn2');
var oBox = document.getElementById('box');
oBtn1.onclick = function(){
  oBox.classList.add('animated');
  oBox.classList.add('flash');
}
oBtn2.onclick = function(){
  oBox.classList.remove('flash');
}
</script>
</body>
</html>

  至于动画的配置参数,比如动画持续时间,动画的执行次数等等,可以在元素上自行定义,覆盖掉animate.css里面所定义的就行了 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://unpkg.com/animate.css@3.5.2/animate.min.css">
<style>
.box{height: 100px;width: 100px;background-color: lightblue}
.infinite{animation-iteration-count:infinite;}
</style>
</head>
<body>
<button id="btn1">添加循环的动画效果</button>
<button id="btn2">移除</button>
<div id="box" class="box"></div>
<script>
var oBtn1 = document.getElementById('btn1');
var oBtn2 = document.getElementById('btn2');
var oBox = document.getElementById('box');
oBtn1.onclick = function(){
  oBox.classList.add('animated');
  oBox.classList.add('flash');
  oBox.classList.add('infinite');
}
oBtn2.onclick = function(){
  oBox.classList.remove('flash');
}
</script>
</body>
</html>

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/154239.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • python中setattr用法_python中hasattr()、getattr()、setattr()函数的使用

    python中setattr用法_python中hasattr()、getattr()、setattr()函数的使用引言 在阅读源码时 有很多简写的形式 其中一个比较常用的就是 getattr 用来调用一个类中的变量或者方法 相关联的 hasattr getattr setattr 函数的使用也一并学习了一下 正文 1 hasattr object name 判断 object 对象中是否存在 name 属性 当然对于 python 的对象而言 属性包含变量和方法 有则返回 True 没有则返回 False 需要注

    2025年11月26日
    8
  • python读取图像数据的一些方法[通俗易懂]

    python读取图像数据的一些方法[通俗易懂]工作和学习中设计一个神经网络中经常需要设计一个数据载入器。首先第一件事我们要根据我们的任务要求确定一个数据提供的方法。如我们是一个分类任务,我们就需要读取数据和数据本身对应的标签。12除了分类任务之外当然还有一些图像到图像的任务,如…

    2025年10月30日
    4
  • StringUtils常用方法「建议收藏」

    StringUtils常用方法「建议收藏」StringUtils 方法的操作对象是 java.lang.String 类型的对象,是对 JDK 提供的 String 类型操作方法的补充,并且是 null 安全的(即如果输入参数 String 为 null 则不会抛出  NullPointerException ,而是做了相应处理,例如,如果输入为 null 则返回也是 null 等,具体可以查看源代码)。除了构造器,StringU

    2022年4月30日
    39
  • client denied by server configuration[通俗易懂]

    client denied by server configuration

    2022年3月7日
    50
  • mybatis动态sql,常用元素介绍

    mybatis动态sql,常用元素介绍mybatis 动态 sqlif 元素 choose when otherwisefor 元素 bing 元素 if 元素 choose when otherwisefor 元素 bing 元素

    2025年9月5日
    3
  • 怎么解决myeclipse带入乱码_myeclipse控制台乱码

    怎么解决myeclipse带入乱码_myeclipse控制台乱码怎么解决Myeclipse导入项目中文乱码?Myeclipse之所以会出现乱码问题是因为Myeclipse编辑器选择的编码规则是可变的。下面,小编就为大家介绍下解决Myeclipse导入项目中文乱码方法。一、将整个project设置编码UTF-8(UTF-8可以最大的支持国际化):windows-》Preferences-》general-》Workspace-》Textfileencodi…

    2025年6月18日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号