Skip to content

Commit 18ee2e8

Browse files
committed
cache classes
1 parent bac64b4 commit 18ee2e8

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

Readme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11

22
# animate-css
33

4-
Apply css animations to an element, with a callback for when that animation finishes. If the browser doesn't support transitions, the callback is invoked immediately.
4+
A small helper for applying CSS animations to an element, with a callback for when that animation finishes. If the browser doesn't support transitions, the callback is invoked immediately. It works well with [animate.css](https://github.com/daneden/animate.css) animations.
55

66
## Installation
77

88
$ component install bmcmahen/animate-css
99

1010
## API
1111

12-
var animate = require('bmcmahen-animate');
12+
var animate = require('bmcmahen-animate-css');
13+
var el = document.getElementById('animate-me');
1314
animate(el, 'fadeOutRight', function(element){
14-
$(element).remove();
15+
// Element has finished animating
1516
});
1617

1718

component.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
2-
"name": "animate",
3-
"repo": "bmcmahen/animate",
2+
"name": "animate-css",
3+
"repo": "bmcmahen/animate-css",
44
"description": "a jquery like api for animations, but for css",
55
"version": "0.0.1",
66
"keywords": [],
77
"dependencies": {
88
"component/classes": "*",
9-
"ecarter/css-emitter": "*"
9+
"ecarter/css-emitter": "*",
10+
"bmcmahen/transition-property": "*",
11+
"component/once": "*"
1012
},
1113
"development": {},
1214
"license": "MIT",

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ function animate(el, className, fn){
1818
if (fn) fn(el);
1919
return;
2020
}
21-
classes(el).add(className);
21+
var cls = classes(el);
22+
cls.add(className);
2223
cssEvent(el).bind(once(cleanup));
2324
function cleanup(){
24-
classes(el).remove(className);
25+
cls.remove(className);
2526
if (fn) fn(el);
2627
}
2728
}

tests/test.html

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,67 @@
11
<html>
22
<head>
33
<title></title>
4+
<style>
5+
#hello {
6+
width: 400px;
7+
height: 400px;
8+
background: #eee;
9+
}
10+
11+
.animated {
12+
-webkit-animation-duration: 1s;
13+
-moz-animation-duration: 1s;
14+
-o-animation-duration: 1s;
15+
animation-duration: 1s;
16+
-webkit-animation-fill-mode: both;
17+
-moz-animation-fill-mode: both;
18+
-o-animation-fill-mode: both;
19+
animation-fill-mode: both;
20+
}
21+
22+
@-webkit-keyframes bounce {
23+
0%, 20%, 50%, 80%, 100% {-webkit-transform: translateY(0);}
24+
40% {-webkit-transform: translateY(-30px);}
25+
60% {-webkit-transform: translateY(-15px);}
26+
}
27+
28+
@-moz-keyframes bounce {
29+
0%, 20%, 50%, 80%, 100% {-moz-transform: translateY(0);}
30+
40% {-moz-transform: translateY(-30px);}
31+
60% {-moz-transform: translateY(-15px);}
32+
}
33+
34+
@-o-keyframes bounce {
35+
0%, 20%, 50%, 80%, 100% {-o-transform: translateY(0);}
36+
40% {-o-transform: translateY(-30px);}
37+
60% {-o-transform: translateY(-15px);}
38+
}
39+
@keyframes bounce {
40+
0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
41+
40% {transform: translateY(-30px);}
42+
60% {transform: translateY(-15px);}
43+
}
44+
45+
.bounce {
46+
-webkit-animation-name: bounce;
47+
-moz-animation-name: bounce;
48+
-o-animation-name: bounce;
49+
animation-name: bounce;
50+
}
51+
52+
</style>
453
</head>
554
<body>
655

56+
<div id='hello' class='animated'><p> hi there </p></div>
757
<script src='../build/build.js' type='text/javascript'></script>
858
<script>
9-
var transitionEnd = require('animate');
10-
console.log(transitionEnd);
59+
var animate = require('animate-css');
60+
var div = document.getElementById('hello');
61+
animate(div, 'bounce', function(el){
62+
console.log(el);
63+
});
64+
1165
</script>
1266

1367
</body>

0 commit comments

Comments
 (0)