A streamlined Sass port (featuring the best) of Dan Eden's Animate.css
Here's the deal: Dan Eden's Animate.css is a wonderful little library. Some of the animations are a little "too much" for my taste and many of the projects I work on. I know there are Sass ports out there (animate.sass and this updated fork), but I wanted a simpler port to Sass that I could build on.
Here is the fruit of this work.
- Use
@include "animated/animated";to bring the library into your Sass project. - Use the
animation mixin globally for every animation you want to include:@include animation(animation-name);. This is important as it brings in the appropriatekeyframe` animation for use in your elements. (Note: the keyframe animation needs to be global in your Sass, and not under any speficic selector, class, ID, or other mixin). - Use the
animatemixin within any element to setup the animation:@include animate(animation-name, animation-duration, animation-delay);.
Here is an example Sass file:
@import "animated/animated";
@include animation(fade-in-down);
@include animation(fade-in);
nav {
@include animate(fade-in-down, 1s);
}
.masthead {
@include animate(fade-in, 1s, 500ms);
}From this we can see that we have our nav element coming in using the fade-in-down animation with a duration of 1 second. The .masthead also fades in with a 1 second duration, but the effect is delayed in its start by 500 milliseconds.
That's it! You can tweak animation-name in your animate mixin call, as well as animation-duration and animation-delay to get your desired effect.
The animation mixin has a single attribute and must be called globally in your Sass project:
animation-name: required
The animate mixin must be called within an element and it has three attributes:
animation-name: required; no defaultanimation-duration: optional; accepts milliseconds or seconds (e.g.500msor1s); default value is 1sanimation-delay: optional; accepts milliseconds or seconds (e.g.500msor1s); no default
Here is a list of all animations included in this library. Reference Dan Eden's original project for animation examples. Use the strings below in Sass in place of the animation-name in the animation and animate mixins:
bouncepulserubber bandshakewobble
bounce-inbounce-in-downbounce-in-leftbounce-in-rightbounce-in-up
bounce-outbounce-out-downbounce-out-leftbounce-out-rightbounce-out-up
fade-infade-in-downfade-in-down-bigfade-in-leftfade-in-left-bigfade-in-rightfade-in-right-bigfade-in-upfade-in-up-big
fade-outfade-out-downfade-out-down-bigfade-out-leftfade-out-left-bigfade-out-rightfade-out-right-bigfade-out-upfade-out-up-big
flip-in-x
slide-in-downslide-in-leftslide-in-rightslide-out-leftslide-out-rightslide-out-up
I also created a simple mixin to handle simpler, "one-off" animations. This mixin doesn't have any keyframe animations so it just needs to be added to any selector, class, or ID in your Sass. Here are usage instructions:
- Call
animate-simplein your Sass, supplying a CSS element, an animation duration (in seconds or milliseconds), and an animation timing function.
The animate-simple mixin must be called within any CSS element and it has three attributes:
css-attribute: optional; defaults tocolorif no attribute is specified (examples arebackground-color,border-color, anccoloralthough any CSS attribute can be used)animation-duration: optional; accepts milliseconds or seconds (e.g.500msor1s); default value is 300msanimation-timing-function: optional; defaults toease-in-out
Here is a sample piece of code:
a {
&:hover {
@include animate-simple();
@include animate-simple(border-color, 200ms, ease-in);
}
}
In this code, you can see that there are two animations being called. The first call animates the <a> element on hover with the default CSS attribute color with an animation-duration of 300ms and the default timing function: ease-in-out. The second animation animates the link's border-color with a duration of 200ms and the animation timing function: ease-in.
This project is a work in progress and my first Sass plugin. Feel free to get in touch if you want to see changes. My arm could probably be twisted to include Dan Eden's entire library. I just chose these animations because there is a subtlty to them that I appreciate and will be able to utilize in my projects. If it's helpful to you, great! If there is a better way to Sassify this project, feel free to reach out as I'm always willing to learn better ways to do things. I have done here what makes sense and hopefully it is helpful to you in some small way.
Major thanks go to @daneden for the awesome CSS library of animations he compiled. Also thanks to @polikin for the inspiration. Also, thank you to Sache and the wonderful Sass community for helping make the web a better, more organized, and more beautiful place.
The MIT License (MIT)
Copyright (c) 2013-2014 Simko Design
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.