ng-Animate doesn't remove add classes angular 1.2.x - angularjs

I am trying to have an icon animate while loading and stop the animation once loading is complete. I was attempting this by activating a class based on a refreshing property. This worked in AngularJS 1.2.0-rc.3, but now (have tried 1.2.3 and 1.2.4) the animation never stops, and I believe the reason is that the -add classes that are added are not removed when the bound variable changes to false.
Here is the plunker demonstrating.
http://plnkr.co/edit/fbcCPxwZtcIoS0ZqrHhf?p=preview
Interesting that more toggles of the variable eventually do stop the animation. Is what I am trying to do valid, I suppose I could always just show hide a loading gif, but I liked the idea of animating the existing image
Thanks!
Curt

The problem is in your css.
You don't need '.icon-refresh-animate-add'.
Use this css class:
.icon-refresh-animate {
animation-name: rotateThis;
animation-duration: .5s;
animation-iteration-count: infinite;
animation-timing-function: linear;
-webkit-animation-name: rotateThis;
-moz-animation-name: rotateThis;
-webkit-animation-duration: .5s;
-moz-animation-duration: .5s;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-timing-function: linear;
}
It's a carbon copy of your animate-add.
Explanation: The ngClass is turning the .icon-refresh-animate class on and off. So when the state is true the class is applied and the animation loops forever. When the state is false the css class is removed so there will be no animation at all. So this bit of code does all the work for you
ng-class="{'icon-refresh-animate':refreshing}"
And here's the full CSS:
#keyframes rotateThis {
from {
transform: scale(1) rotate(0deg);
}
to {
transform: scale(1) rotate(360deg);
}
}
#-webkit-keyframes rotateThis {
from {
-webkit-transform: scale(1) rotate(0deg);
}
to {
-webkit-transform: scale(1) rotate(360deg);
}
}
.icon-refresh-animate {
animation-name: rotateThis;
animation-duration: .5s;
animation-iteration-count: infinite;
animation-timing-function: linear;
-webkit-animation-name: rotateThis;
-moz-animation-name: rotateThis;
-webkit-animation-duration: .5s;
-moz-animation-duration: .5s;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-timing-function: linear;
}

Related

Animating UI Router using #keyframes not working

I am attemping to animate the ui-router using #keyframes property.
What I want to achieve is that when the user clicks on an item in the menu, the page to come flying in
Doesn't seem to be working as expected.
#keyframes page-slide {
0% {left:100%; top:0px;}
25% {left:75%; top:0px;}
50% {left:50%; top:0px;}
75% {left:25%; top:0px;}
100% {left:0%; top:0px;}
}
Any clue what I could be missing here ?
Link to Plnkr: http://plnkr.co/edit/CXNaNogXwn8Vzg8rugDT?p=info
If you just wanna use CSS you need to wrap the position:absolute with a position:relative container. Also set the height: 100% for all the containers.
http://embed.plnkr.co/xOEgPjvNtfpcQAxj6rWY/preview
.container {
position: relative;
height: 100%;
}
.page-transition {
width: 100%;
height: 100%;
position: absolute;
animation-name: page-slide;
animation-duration: 4s;
}
#keyframes page-slide {
0% {left:100%; top:0px;}
25% {left:75%; top:0px;}
50% {left:50%; top:0px;}
75% {left:25%; top:0px;}
100% {left:0%; top:0px;}
}
What exactly is not working as expected?
If you want the animation to run more "fluidly" just define start and end:
#keyframes page-slide {
from {left:100%; top:0px;}
to {left:0%; top:0px;}
}
Or using translate3d
#keyframes page-slide {
from {
transform: translate3d(100%, 0, 0);
}
to {
transform: translate3d(0, 0, 0);
}
}
Here a link to your example with the changes I made: http://embed.plnkr.co/7bTcKhLWJmm4hXkdcRvN/preview

Angular UI Router: ui-view positioning on state change

I am currently developing a heavy angular-driven homepage for an agency. Now I am at the state-change. I added a page transition with a simple fade effect. Now the problem I have is, that the new ui-view that is being added when the state changes is prepended before the first ui-view. Everything alright, but as the first ui-view is fading out the second is already added and the transition looks just crappy. So, I want to have the new ui-view added after the first ui-view.
IMPORTANT: I am using parallax effects, so the solution with a page-container and absolute positioning isn't possible.
This image is showing what I want to have afterwards.
I had faced similar issue, it was because I had animation on both enter and leave.
You dont need animation on both enter and leave.
You can have animation only on leave or only on enter
E.g.
.ng-enter {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
opacity: 0;
}
checkout the easing in animation in this PLUNKER
OR if you want animation in both enter and leave, then add a delay in animation
add delay to your transitions:
.ng-enter{
-webkit-transition: all 2s ease 1s;
-moz-transition: all 2s ease 1s;
-o-transition: all 2s ease 1s;
transition: all 2s ease 1s;
}
.ng-leave {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
}
Building off of #HarishR's answer:
http://plnkr.co/edit/pzsDd1zPvHgdZe099upi?p=preview
We have 2 transitions:
IN:
.ng-enter {
transition: opacity 1s ease; // autoprefixer
opacity: 0; // start animating
}
.ng-enter-active {
opacity: 1; // end animating
}
OUT:
.ng-exit {
transition: opacity 1s ease; // autoprefixer
opacity: 1; // start animating
}
.ng-exit-active {
opacity: 0; // end animating
}
This will take 1 second to fade in and out the blocks. When there's only 1 block, it fades in immediately over 1 second. What if there are two blocks though (transitioning from one to another?). We can use delays and some nifty css:
// Selector only matches if 2 sibling animating elements exist
.ng-animate + .ng-animate {
// Avoid pushing around DOM
// Property disappears once the first sibling leaves
position:absolute;
// Delay fade-in until first sibling leaves
transition-delay: 1s; // autoprefixer
}
Without this fancy selector, the first time you open a view you'd have a 1s delay before anything happens.

lock a page/form using $animate. angularjs

I need to create a form locker with progress bar or spinner dynamically .
https://github.com/chieffancypants/angular-loading-bar/blob/master/src/loading-bar.css has the code for the spinner but it just displays the spinner and not locking the form..
Is there any way to lock the form page once the spinner is loaded so that no more actions are done .
start the spinner
this.parentSelector = 'body';
var $parentSelector = this.parentSelector,
var $parent = $document.find($parentSelector);
spinner = angular.element('<div id="loading-bar-spinner"><div class="spinner-icon"></div></div>');
{
$animate.enter(spinner, $parent);
}
css :
#loading-bar-spinner {
pointer-events: none;
-webkit-pointer-events: none;
-webkit-transition: 350ms linear all;
-moz-transition: 350ms linear all;
-o-transition: 350ms linear all;
transition: 350ms linear all;
}
#loading-bar.ng-enter,
#loading-bar.ng-leave.ng-leave-active,
#loading-bar-spinner.ng-enter,
#loading-bar-spinner.ng-leave.ng-leave-active {
opacity: 0;
}
#loading-bar.ng-enter.ng-enter-active,
#loading-bar.ng-leave,
#loading-bar-spinner.ng-enter.ng-enter-active,
#loading-bar-spinner.ng-leave {
opacity: 1;
}
#loading-bar-spinner {
display: block;
position: fixed;
z-index: 10002;
top: 300px;
left: 200px;
}
#loading-bar-spinner .spinner-icon {
width: 14px;
height: 14px;
border: solid 22px yellow;
border-top-color: #29d;
border-left-color: #29d;
border-radius: 120px;
-webkit-animation: loading-bar-spinner 400ms linear infinite;
-moz-animation: loading-bar-spinner 400ms linear infinite;
-ms-animation: loading-bar-spinner 400ms linear infinite;
-o-animation: loading-bar-spinner 400ms linear infinite;
animation: loading-bar-spinner 400ms linear infinite;
}
#-webkit-keyframes loading-bar-spinner {
0% { -webkit-transform: rotate(0deg); transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); }
}
#-moz-keyframes loading-bar-spinner {
0% { -moz-transform: rotate(0deg); transform: rotate(0deg); }
100% { -moz-transform: rotate(360deg); transform: rotate(360deg); }
}
#-o-keyframes loading-bar-spinner {
0% { -o-transform: rotate(0deg); transform: rotate(0deg); }
100% { -o-transform: rotate(360deg); transform: rotate(360deg); }
}
#-ms-keyframes loading-bar-spinner {
0% { -ms-transform: rotate(0deg); transform: rotate(0deg); }
100% { -ms-transform: rotate(360deg); transform: rotate(360deg); }
}
#keyframes loading-bar-spinner {
0% { transform: rotate(0deg); transform: rotate(0deg); }
100% { transform: rotate(360deg); transform: rotate(360deg); }
}
I recomend using open-source on those components.
I have good experience with blockUI.
Features:
You can add your own spinner.
You can decide to run the spinner on each server call(by default) or you can control it youself.
It's super simple to integrate\config as a module.

AngularJS 1.2 ng-show height animation

I'm trying to get a height animation working using Angular JS 1.2. I've got a plunker here that has the animation working for closing the item:
http://plnkr.co/edit/YVtnXgjO3Evb6tz5DJOp?p=preview
With the key bit being this CSS here:
.accordion-body {
height: 100px;
-webkit-transition: 0.5s linear all;
transition: 0.5s linear all;
}
.accordion-body.ng-hide-add,
.animate-show.ng-hide-remove {
display: block !important;
}
.accordion-body.ng-hide-add{
}
.accordion-body.ng-hide-remove{
}
.accordion-body.ng-hide {
height:0;
}
But I can't figure out how to get it to work for opening the item. I'm obviously doing something braindead - what am I missing?
Got it working with the following CSS:
.accordion-body {
height: 100px;
-webkit-transition: 0.5s linear all;
transition: 0.5s linear all;
}
.accordion-body.ng-hide-add,
.accordion-body.ng-hide-remove {
display: block !important;
height: 0px;
}
.accordion-body.ng-hide-remove.ng-hide-remove-active {
height: 100px;
}
.accordion-body.ng-hide-add{
height: 100px;
}
.accordion-body.ng-hide-add.ng-hide-add-active {
height: 0;
}
You messed up a class name is all.

ngHide and ngAnimate with max-width: transition property on the wrong class?

I'm using ngAnimate to animate max-height for a simple slide-toggle effect, and there's something a bit strange happening: when hiding, it seems that setting the transition property on the setup class (.xxx-hide) doesn't work--the height snaps to 0 immediately:
.controls-hide {
-webkit-transition-duration: 1s;
-moz-transition-duration: 1s;
-o-transition-duration: 1s;
transition-duration: 1s;
max-height: 5em;
opacity: 1;
}
.controls-hide.controls-hide-active {
max-height: 0em;
opacity: 0;
}
But setting it on the active class (.xxx-hide.xxx-hide-active), the animation works just fine:
.othercontrols-hide {
opacity: 1;
max-height: 5em;
}
.othercontrols-hide.othercontrols-hide-active {
-webkit-transition-duration: 1s;
-moz-transition-duration: 1s;
-o-transition-duration: 1s;
transition-duration: 1s;
max-height: 0em;
opacity: 0;
}
(Here's the whole fiddle.)
Even more strangely, the opacity animates just fine in both cases. What's going on here?
I just follow the instructions at this site: http://www.nganimate.org/angularjs/ng-repeat/appear
And I got this fiddle working: http://jsfiddle.net/WXWSu/2/
What I changed was set the transtion tag to all changes (transition: 1s linear all;), and set the start properties at the main class:
.exercise-controls {
overflow: hidden;
border: 1px solid black;
height: 5em;
opacity: 1;
}

Resources