Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

during ng-animate of views, "leaving" view still takes up space while "entering" view is animating in

I'm using AngularJS 1.1.5 and trying out the ng-animate directive with daneden's animate.css. I have a couple of views set up using routing. I'm using Twitter Bootstrap 3 RC1.

Here is the code for the ng-view:

<div class="container" ng-view ng-animate="{enter:'animated fadeInRightBig', leave:'animated fadeOutLeft'}"></div>

And here is the routing part:

$routeProvider
    .when('/', {
        templateUrl: '/Home/Home',
        title: 'Home'
    })
    .when('/Home/Home', {
        templateUrl: '/Home/Home',
        title: 'Home'
    })
    .when('/Home/About', {
        templateUrl: '/Home/About',
        title: 'About'
    })
    .otherwise({
        redirectTo: '/'
    });

    $locationProvider.html5Mode(false).hashPrefix('!');

The animation works (that is, I see the animation effects) and the view changes as well.

The thing I'm having trouble with is that the "leaving" view seems to be still taking up space while the "entering" view is animating in.

The effect is that the enter animation of the new view happens below the space previously taken up by the leaving view. It's as if the old view was still there, even though it has already "animated out". The new view then suddenly jerks up to the proper position once its animation finishes. I'm using fadeInRightBig for enter and fadeOutLeft for leave.

How can this be fixed? The expected result is a smooth transition with no jerking, like the animation for the ng-switch in slides 1 to 3 here. (Except that I'm using ng-view of course.)

Thanks!

Edit:

I take it back, the 'leave' animation hasn't completely finished while the 'enter' animation is running.

So I guess my question will change a bit.. But the expected result is the same. How do I achieve the smooth "sliding" effect?

like image 283
OJ Raqueño Avatar asked Aug 04 '13 13:08

OJ Raqueño


People also ask

Which of the following are valid easing functions in angular animations?

The easing value controls how the animation accelerates and decelerates during its runtime. Value is one of ease , ease-in , ease-out , ease-in-out , or a cubic-bezier() function call. If not supplied, no easing is applied.

What is angular animation?

Angular's animation system is built on CSS functionality, which means you can animate any property that the browser considers animatable. This includes positions, sizes, transforms, colors, borders, and more. The W3C maintains a list of animatable properties on its CSS Transitions page.

What is ngAnimate module?

The ngAnimate module adds and removes classes. The ngAnimate module does not animate your HTML elements, but when ngAnimate notice certain events, like hide or show of an HTML element, the element gets some pre-defined classes which can be used to make animations.


2 Answers

I had the same issue when I first started. To achieve the smooth effect simply change the timings of the CSS. Go into the animate.css file, look for the one the one you need to delay (in your case it would be fadeInRightBig. Change delay (or add a delay to it of about 1 or 2 seconds).

Another alternative is to make the position of the exit animation absolute.

Let me know if this helps. It worked for me. I wish that angularjs already handled this for us. Maybe the next version will solve these issues for us.

like image 191
Pbrain19 Avatar answered Sep 24 '22 10:09

Pbrain19


Another common way to solve this problem is to deal with z-index. The ng-enter usually must be below the ng-leave.

like image 34
Victor Ivens Avatar answered Sep 21 '22 10:09

Victor Ivens