Animate Angular apps with ngFx
Update: To use this tool there are some licensing restrictions. If you’re charging people money to use your app you’ll need a license. :Sad face:
If you would like to see the source code it is on github.
I set up a lightweight angular starter template with ui-router and no clunky build system. Clone it and add the ngFx module, TweenMax library and the ngAnimate module to take care of dependencies. You could also use bower if that is easier for you. Add the modules to the app.
So to start off we’re going to click a button and show a login form. I set up an additional state with the same controller.
Then made a basic login form with a show form button.
Then there’s the controller
And a little bit of css to prettify (not to animate).
So out of all that code and markup, the only bit that added animation was the
fx-fade-down class on the html form’s parent. The module uses the fx namespace, so any class prefixed with
All dynamic animations tie into ngAnimate hooks. So you can apply them to…
- ng-hide / ng-show
- ui-view (if you’re using ui.router)
This means that these directives are all “animate aware”1. So when the ng-show binding changes a fade down animation occurs on the element. Right now we trigger the change by clicking an element. So far it’s pretty cool.
Pro tip: With bootstrap
<div class="img-rounded"> will give you rounded corners on any element.
So looking at the list above, we can add animations for every time a page comes in. In index.html
We can add more complex animations with easings, speeds, directives and event hooks. This is a basic introduction to how to use this module for a project.
The source code is HERE. If you would like to build on this please submit a pull request!