I am here to continue the discussion around AngularJS. Today, we will discuss how to create mobile device related animation using angular js. Also in case you have not had a look at our previous articles of this series, go through the following links:
- Learn AngularJS From Beginning: Basic - Part One
- Learn AngularJS From Beginning: Filter - Part Two
- Learn AngularJS From Beginning: Service - Part Three
- Learn AngularJS From Beginning: Directive - Part Four
- Learn AngularJS From Beginning: Form Data Binding - Part Five
- Learn AngularJS From Beginning: Global Object Service - Part Six
- Learn AngularJS From Beginning: Http Request or Ajax - Part Seven
- Learn AngularJS From Beginning: Rest API - Part Eight
- Learn AngularJS From Beginning: Route Url - Part Nine
- Learn AngularJS From Beginning: Animation - Part Ten
- Learn AngularJS From Beginning: Injection - Part Eleven
- Learn AngularJS From Beginning: Localisation - Part Twelve
- Learn AngularJS From Beginning: Unit Test of AngularJS Controller - Part Thirteen
- Learn AngularJS From Beginning: Unit Test of AngularJS Component - Part Fourteen
- Learn AngularJS From Beginning: Automatic Workflow (Grunt) - Part Fifteen
- Learn AngularJS From Beginning: Lazy Loading of Angular Files - Part Sixteen
- Learn AngularJS From Beginning: Google Map API - Part Seventeen
- Learn AngularJS From Beginning: Custom Animation - Part Eighteen
In the previous articles, we already discussed how to create animations using both JavaScript and CSS in the AngularJS context for native and custom directives. Now, in this article, we will learn how to enhance the user experience of our AngularJS web app, especially on mobile devices and tablets.
Enhance UX on mobile devices with animations
With the increasing use of smartphones and tablet devices, more people have started to visit websites via smartphones and other devices, so not optimizing a web app for small devices is not an option anymore. Nowadays, we create a single web app that is responsive to the device width using CSS3 media queries. So, we are able to define different styles for each device width size. We can provide a better experience based on the screen size. Currently, web apps are run on small screens of devices such as smartphones and also on screens as big as that of TVs. It's impossible to create a CSS style for each device width in the world, so usually, we work with different ranges of screen widths: smartphones, tablets and small desktops, and big desktops monitors. As we usually use CSS animations to animate in the AngularJS context, we are able to define animations in a specific media query. So, we might disable some heavy-processing animations and enable other GPU-accelerated animations for small screens.
The motion created by animations on web apps is better delivered when it seems more realistic. One of the material design guidelines is to avoid linear animations as it's a more mechanical and artificial movement than animations with acceleration and deceleration at the beginning and ending of an animation curve. This guideline is called authentic motion. Another important guideline is meaningful transitions, the next section's subject.
Transition between views
The Google material design website explains transitioning as follows:
"Transitioning between two visual states should be smooth, appear effortless, and above all, provide clarity to the user, not confusion. A well-designed transition does the heavy lifting and enables the user to clearly understand where their attention should be focused. A transition has three categories of elements."
- <!DOCTYPE html>
- <html ng-app="myApp">
- <head>
- <title>AngularJS Swipe Slider animation</title>
- <meta name="viewport" content="width=device-width,height=deviceheight,user-scalable=no">
- <link href="mobile.css" rel="stylesheet" />
- <link href="bootstrap.css" rel="stylesheet" />
- <script src="angular.min.js"></script>
- <script src="angular-touch.min.js"></script>
- <script src="angular-animate.min.js"></script>
- <script src="tabsSwipeCtrl.js"></script>
- </head>
- <body>
- <div ng-controller="tabsSwipeCtrl as responsive">
- <div class="btn-group btn-group-justified">
- <div class="btn-group">
- <button type="button" class="btn btn-default" ngclick="responsive.selectPage(0)" ng-class="{'active': responsive.ngIncludeSelected.index == 0}">
- First
- </button>
- </div>
- <div class="btn-group">
- <button type="button" class="btn btn-default" ngclick="responsive.selectPage(1)" ng-class="{'active': responsive.ngIncludeSelected.index == 1}">
- Second
- </button>
- </div>
- <div class="btn-group">
- <button type="button" class="btn btn-default" ngclick="responsive.selectPage(2)" ng-class="{'active': responsive.ngIncludeSelected.index == 2}">
- Third
- </button>
- </div>
- <div class="btn-group">
- <button type="button" class="btn btn-default" ngclick="responsive.selectPage(3)" ng-class="{'active': responsive.ngIncludeSelected.index == 3}">
- Fourth
- </button>
- </div>
- </div>
- <div class="ngIncludeRelative">
- <div class="ngIncludeItem" ng-include="responsive.ngIncludeSelected.url" ng-class="{'moveToLeft' : responsive.moveToLeft}"></div>
- </div>
- </div>
- </body>
- </html>
We added the ngSwipeLeft and ngSwipeRight directives from the ngTouch module to the partial view, so the user can change between views by swiping gestures.
FirstSwipe.html
Vignesh ManiPosted May 27, 2016, 4:21 PM
nice
Sonu ChaudharyPosted May 27, 2016, 4:12 PM
good one
Munesh SharmaPosted May 27, 2016, 2:01 PM
nice work