16.07.2017 Views

AngularJS Essentials

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

This is quite a simple mechanism, but we need to pay careful attention in order to<br />

understand it.<br />

Chapter 2<br />

Animating ngRepeat<br />

The following code is a simple example where we will animate the enter event of<br />

the ngRepeat directive:<br />

app.css<br />

.ng-enter {<br />

-webkit-transition: all 5s linear;<br />

-moz-transition: all 5s linear;<br />

-ms-transition: all 5s linear;<br />

-o-transition: all 5s linear;<br />

transition: all 5s linear;<br />

opacity: 0;<br />

}<br />

.ng-enter-active {<br />

opacity: 1;<br />

}<br />

That's all! With this configuration in place, every time a new element is rendered<br />

by an ngRepeat directive, it will respect the transition, appearing with a 5 second,<br />

linear, fade-in effect from the opacity 0 to 1.<br />

For the opposite concept, we can follow the same process. Let's create a fade-out<br />

effect by means of the .ng-leave and .ng-leave-active classes:<br />

app.css<br />

.ng-leave {<br />

-webkit-transition: all 5s linear;<br />

-moz-transition: all 5s linear;<br />

-ms-transition: all 5s linear;<br />

-o-transition: all 5s linear;<br />

transition: all 5s linear;<br />

opacity: 1;<br />

}<br />

.ng-leave-active {<br />

opacity: 0;<br />

}<br />

[ 49 ]<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!