Book Image

Learning AngularJS Animations

By : Richard Keller
Book Image

Learning AngularJS Animations

By: Richard Keller

Overview of this book

Table of Contents (15 chapters)
Learning AngularJS Animations
About the Author
About the Reviewers


The AngularJS framework is a turning point in the evolution of web development. It really helps developers to produce professional web apps by writing less JavaScript code.

The ngAnimate module, developed by the core team of AngularJS and the open source community, integrated AngularJS features with animation web standards, providing all the benefits from standardization with AngularJS development patterns.

Before animations were introduced to AngularJS, integrating animations was a bit tricky, as in AngularJS, changes to the model affect the view implicitly (it's part of the two-way data binding concept). In other words, the DOM life cycle management is often controlled by the AngularJS core and animations should be triggered in between those manipulations. To solve this problem, the ngAnimate module was written and redesigned to be completely based on CSS classes. This means that animations should be applied based on element classes. Classes are appended or removed from elements on specific events, so we are able to apply animations as the entry of an element on DOM and the imminent exit of an element from DOM.

This book will help you learn from the beginning how to add animations to AngularJS web apps, focusing on the ngAnimate module. It's an optional module in AngularJS because the framework is going in a direction that will allow you to choose which modules to use so that the module can fit your needs and be as light as you desire.

What this book covers

Chapter 1, Getting Started, will introduce you to the history of animations in web development and explain why the AngularJS animation module is so important. Then, you will get started on the modern web standards of animation, introducing you to when to use each of them.

Chapter 2, Understanding CSS3 Transitions and Animations, will teach you how to create animations using CSS transitions, CSS animations, and how to animate using the CSS transform, giving us a good base to start using animations with the AngularJS framework in the next chapter.

Chapter 3, Creating Our First Animation in AngularJS, will walk you through setting up an AngularJS application using the ngAnimate module. Then, we will create basic animations using CSS transitions and an animation keyframe integrated with AngularJS native directives. This chapter will introduce the AngularJS directives that support animation events.

Chapter 4, JavaScript Animations in AngularJS, will tell you how to create animations using JavaScript and create animations with jQuery integrated with AngularJS native directives. You will learn how to create animations using CSS and JavaScript as a fallback when the browser does not support CSS animations.

Chapter 5, Custom Directives and the $animate Service, will teach you how to use CSS animations together with custom directives by giving you an overview of what happens in the life cycle of an AngularJS animation inside the $animate service. Then, it will teach you how to create animations in custom directives using only JavaScript.

Chapter 6, Animations for Mobile Devices, will help you apply animations to enhance usability on smartphones and small devices and introduces the Google material design, a guideline for mobile development.

Chapter 7, Staggering Animations, will teach you how to create animations that appear in a consistent sequence, which are usually difficult to create without the ngAnimate module, and can improve user experience. This chapter will teach you the rules to be followed and how to apply these animations in native and custom directives.

Chapter 8, Animations Performance Optimization, will provide you with an introduction to animation performance diagnostics and solutions by teaching you how to find performance bottlenecks using Chrome DevTools. Then, it will teach you about rendering layers and animations that you should avoid or are that replaced by others.

What you need for this book

In order to run the example code in this book, you will need a modern web browser such as Google Chrome, IE10 or newer, Safari, or Firefox, as support for CSS animations and CSS transitions is mandatory.

A basic text editor is mandatory to test samples and answer exercises.

Source files of AngularJS and angular animate are needed too, although we will use a CDN for all samples.

Who this book is for

This book is intended for those who are familiar with the AngularJS framework, as we will focus on the animations module. You need to know the basics of HTML and CSS. Some previous knowledge about the most essential AngularJS directives (such as ngRepeat, ngView, ngIf, and ngSwitch) is expected, but no previous knowledge of JavaScript animations, CSS3 animations, or any animations library is required.

By reading this book, you will be prepared to create animations and integrate them with AngularJS web apps.


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "First we created an animation with JavaScript without requestFrameRate."

A block of code is set as follows:

var app = angular.module('myApp', ['ngAnimate'])
    .animation(".firstJsAnimation", firstJsAnimation); 

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

  <script src="//"></script>
  <script src="//"></script>
    var app = angular.module('myApp', ['ngAnimate']);

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "For this sample, we have a Toggle fade button that changes the ngShow model value, so we can see what happens when the element fades in and fades out from the DOM."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from:


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from


Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.


You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.