animate.css/README.md

240 lines
8.4 KiB
Markdown
Raw Normal View History

# Animate.css [![GitHub release](https://img.shields.io/github/release/daneden/animate.css.svg)](https://github.com/daneden/animate.css/releases) [![CDNJS](https://img.shields.io/cdnjs/v/animate.css.svg)](https://cdnjs.com/libraries/animate.css) [![Build Status](https://travis-ci.com/daneden/animate.css.svg?branch=master)](https://travis-ci.com/daneden/animate.css) [![devDependencies Status](https://david-dm.org/daneden/animate.css/dev-status.svg)](https://david-dm.org/daneden/animate.css?type=dev) [![chat](https://img.shields.io/badge/chat-gitter-green.svg)](https://gitter.im/animate-css/Lobby) [![npm version](https://badge.fury.io/js/animate.css.svg)](https://www.npmjs.com/package/animate.css)
2017-11-16 00:20:46 +01:00
_Just-add-water CSS animation_
2011-12-14 11:14:22 +01:00
`animate.css` is a bunch of cool, fun, and cross-browser animations for you to use in your projects. Great for emphasis, home pages, sliders, and general just-add-water-awesomeness.
## Installation
2017-11-16 00:20:46 +01:00
Install via npm:
2016-06-08 11:00:41 +02:00
```bash
$ npm install animate.css --save
```
or yarn:
2018-10-13 17:04:06 +02:00
```bash
$ yarn add animate.css
```
## Usage
2017-11-16 00:20:46 +01:00
To use animate.css in your website, simply drop the stylesheet into your document's `<head>`, and add the class `animated` to an element, along with any of the animation names. That's it! You've got a CSS animated element. Super!
2014-09-08 17:16:31 +02:00
2017-11-16 00:20:46 +01:00
```html
<head>
<link rel="stylesheet" href="animate.min.css">
</head>
```
or use a CDN hosted version by [CDNJS](https://cdnjs.com/libraries/animate.css)
2017-11-16 00:20:46 +01:00
```html
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css">
2017-11-16 00:20:46 +01:00
</head>
```
### Animations
2014-09-08 17:16:31 +02:00
To animate an element, add the class `animated` to an element. You can include the class `infinite` for an infinite loop. Finally you need to add one of the following classes to the element:
2014-09-08 17:16:31 +02:00
2017-11-16 00:20:46 +01:00
| Class Name | | | |
| ----------------- | ------------------ | ------------------- | -------------------- |
| `bounce` | `flash` | `pulse` | `rubberBand` |
| `shake` | `headShake` | `swing` | `tada` |
| `wobble` | `jello` | `bounceIn` | `bounceInDown` |
| `bounceInLeft` | `bounceInRight` | `bounceInUp` | `bounceOut` |
| `bounceOutDown` | `bounceOutLeft` | `bounceOutRight` | `bounceOutUp` |
| `fadeIn` | `fadeInDown` | `fadeInDownBig` | `fadeInLeft` |
| `fadeInLeftBig` | `fadeInRight` | `fadeInRightBig` | `fadeInUp` |
| `fadeInUpBig` | `fadeOut` | `fadeOutDown` | `fadeOutDownBig` |
| `fadeOutLeft` | `fadeOutLeftBig` | `fadeOutRight` | `fadeOutRightBig` |
| `fadeOutUp` | `fadeOutUpBig` | `flipInX` | `flipInY` |
| `flipOutX` | `flipOutY` | `lightSpeedIn` | `lightSpeedOut` |
| `rotateIn` | `rotateInDownLeft` | `rotateInDownRight` | `rotateInUpLeft` |
| `rotateInUpRight` | `rotateOut` | `rotateOutDownLeft` | `rotateOutDownRight` |
| `rotateOutUpLeft` | `rotateOutUpRight` | `hinge` | `jackInTheBox` |
| `rollIn` | `rollOut` | `zoomIn` | `zoomInDown` |
| `zoomInLeft` | `zoomInRight` | `zoomInUp` | `zoomOut` |
| `zoomOutDown` | `zoomOutLeft` | `zoomOutRight` | `zoomOutUp` |
| `slideInDown` | `slideInLeft` | `slideInRight` | `slideInUp` |
| `slideOutDown` | `slideOutLeft` | `slideOutRight` | `slideOutUp` |
| `heartBeat` |
2014-09-08 17:16:31 +02:00
Full example:
2017-11-16 00:20:46 +01:00
2014-09-08 17:16:31 +02:00
```html
<h1 class="animated infinite bounce delay-2s">Example</h1>
2014-09-08 17:16:31 +02:00
```
[Check out all the animations here!](https://daneden.github.io/animate.css/)
It's possible to change the duration of your animations, add a delay or change the number of times that it plays:
2011-12-14 11:14:22 +01:00
```css
.yourElement {
animation-duration: 3s;
animation-delay: 2s;
animation-iteration-count: infinite;
}
```
2017-11-16 00:20:46 +01:00
## Usage with jQuery
You can do a whole bunch of other stuff with animate.css when you combine it with jQuery. A simple example:
2011-12-14 11:14:22 +01:00
```javascript
2011-12-14 11:14:22 +01:00
$('#yourElement').addClass('animated bounceOutLeft');
```
You can also detect when an animation ends:
2014-02-25 16:48:53 +01:00
<!--
Before you make changes to this file, you should know that $('#yourElement').one() is *NOT A TYPO*
http://api.jquery.com/one/
-->
```javascript
2018-01-29 17:53:49 +01:00
// See https://github.com/daneden/animate.css/issues/644
var animationEnd = (function(el) {
var animations = {
animation: 'animationend',
OAnimation: 'oAnimationEnd',
MozAnimation: 'mozAnimationEnd',
WebkitAnimation: 'webkitAnimationEnd',
};
for (var t in animations) {
if (el.style[t] !== undefined) {
return animations[t];
}
}
})(document.createElement('div'));
$('#yourElement').one(animationEnd, doSomething);
```
2016-06-08 11:00:41 +02:00
[View a video tutorial](https://www.youtube.com/watch?v=CBQGl6zokMs) on how to use Animate.css with jQuery here.
2017-11-16 00:20:46 +01:00
**Note:** `jQuery.one()` is used when you want to execute the event handler at most _once_. More information [here](http://api.jquery.com/one/).
It's possible to extend jQuery and add a function that does it all for you:
```javascript
$.fn.extend({
2017-11-16 00:20:46 +01:00
animateCss: function(animationName, callback) {
2018-01-29 17:53:49 +01:00
var animationEnd = (function(el) {
var animations = {
animation: 'animationend',
OAnimation: 'oAnimationEnd',
MozAnimation: 'mozAnimationEnd',
WebkitAnimation: 'webkitAnimationEnd',
};
for (var t in animations) {
if (el.style[t] !== undefined) {
return animations[t];
}
}
})(document.createElement('div'));
2017-11-16 00:20:46 +01:00
this.addClass('animated ' + animationName).one(animationEnd, function() {
$(this).removeClass('animated ' + animationName);
2018-01-29 17:53:49 +01:00
if (typeof callback === 'function') callback();
2017-11-16 00:20:46 +01:00
});
2018-01-29 17:53:49 +01:00
2017-11-16 00:20:46 +01:00
return this;
2017-12-10 14:18:20 +01:00
},
});
```
And use it like this:
```javascript
$('#yourElement').animateCss('bounce');
2017-11-16 00:20:46 +01:00
or;
$('#yourElement').animateCss('bounce', function() {
2018-10-13 17:04:46 +02:00
// Do something after animation
});
```
## Setting _Delay_ and _Speed_
### Delay Class
It's possible to add delays directly on the element's class attribute, just like this:
```html
<div class="animated bounce delay-2s">Example</div>
```
| Class Name | Delay Time |
| ---------- | ---------- |
| `delay-2s` | `2s` |
| `delay-3s` | `3s` |
| `delay-4s` | `4s` |
| `delay-5s` | `5s` |
> _**Note**: The default delays are from 1 second to 5 seconds only. If you need custom delays, add it directly to your own CSS code._
### Slow, Slower, Fast, and Faster Class
It's possible to control the speed of the animation by adding these classes, as a sample below:
```html
<div class="animated bounce faster">Example</div>
```
| Class Name | Speed Time |
| ---------- | ---------- |
| `slow` | `2s` |
| `slower` | `3s` |
| `fast` | `800ms` |
| `faster` | `500ms` |
> _**Note**: The `animated` class has a default speed of `1s`. If you need custom duration, add it directly to your own CSS code._
## Custom Builds
2017-11-16 00:20:46 +01:00
Animate.css is powered by [gulp.js](http://gulpjs.com/), which means you can create custom builds pretty easily. First of all, youll need Gulp and all other dependencies:
2014-02-04 08:51:08 +01:00
```sh
$ cd path/to/animate.css/
$ sudo npm install
```
2016-03-22 14:27:37 +01:00
Next, run `gulp` to compile your custom builds. For example, if you want only some of the “attention seekers”, simply edit the `animate-config.json` file to select only the animations you want to use.
```javascript
"attention_seekers": {
"bounce": true,
"flash": false,
"pulse": false,
"shake": true,
"headShake": true,
"swing": true,
"tada": true,
"wobble": true,
"jello":true
}
```
## Accessibility
Animate.css supports the [`prefers-reduced-motion` media query](https://webkit.org/blog/7551/responsive-design-for-motion/) so that users with motion sensitivity can opt out of animations. On supported platforms (currently only OSX Safari and iOS Safari), users can select "reduce motion" on their operating system preferences and it will turn off CSS transitions for them without any further work required.
## License
2017-11-16 00:20:46 +01:00
Animate.css is licensed under the MIT license. (http://opensource.org/licenses/MIT)
## Contributing
2017-11-16 00:20:46 +01:00
Pull requests are the way to go here. We only have two rules for submitting a pull request: match the naming convention (camelCase, categorised [fades, bounces, etc]) and let us see a demo of submitted animations in a [pen](http://codepen.io). That **last one is important**.