I am working on creating a weather module for my SPA with Angular 1.4 and attempting to fade my a view out as the other fades in, when the user clicks a button to retrieve the forecast for their city.
I have injected the ngAnimate module into my application, and attempted to write some CSS, as well as javascript. However, the animation doesn't work no matter what I try! Maybe I'm missing some fundamental concept of how animations work in angular?
Here is my CSS:
.animate-enter, .animate-leave { -webkit-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; -moz-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; -ms-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; -o-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all; position: relative; display: block; overflow: hidden; text-overflow: clip; white-space:nowrap; } .animate-leave.animate-leave-active, .animate-enter { opacity: 0; width: 0px; height: 0px; } .animate-enter.animate-enter-active, .animate-leave { opacity: 1; width: 150px; height: 30px; opacity: 1; } Here is my main page, where my views are brought in:
<body> <header> <nav class="navbar navbar-default"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand" href="/">AngularJS Weather</a> </div> <ul class="nav navbar-nav navbar-right"> <li><a href="#/" id="home"><i class="fa fa-home"></i> Home</a></li> </ul> </div> </nav> </header> <div class="container" ng-animate="{enter: 'animate-enter', leave: 'animate-leave'}" ng-view></div> </body> My app.js:
var weatherApp = angular.module('weatherApp', ['ngRoute', 'ngResource', 'ngAnimate']); weatherApp.config(['$routeProvider', function($routeProvider) { $routeProvider .when('/', { templateUrl: 'pages/home.html', controller: 'homeController' }) .when('/forecast', { templateUrl: 'pages/forecast.html', controller: 'forecastController' }) .when('/forecast/:days', { templateUrl: 'pages/forecast.html', controller: 'forecastController' }) .otherwise({redirectTo: '/'}) }]) A view example:
<div class="home row"> <div class="col-md-6 col-md-offset-3"> <h4>Forecast by City</h4> <div class="form-group"> <input type="text" ng-model="city" class="form-control" /> </div> <a href="#/forecast" class="btn btn-primary">Get Forecast »</a> </div>
$rootScope.$on($stateChangeStart, func...)and$rootScope.$on($stateChangeSuccess, func...)``$stateChange. Should be place in the.runof your app.js$stateChangeStartevent you can grab HTML tags and set style attribute until the$stateChangeSuccesshappens.