Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ng-animate animations are not triggered atomically between enter and leave on ng-view #3404

@gustly

Description

@gustly

We are running into an issue in our AngularJS 1.1.5 app related to how ng-animate triggers the animations for enter and leave on the ngView directive.

We are doing a "slide left" animation using a CSS transition. We're doing the usual thing where we put an initial state and a transition with a duration on the .slide-left-enter and .slide-left-leave classes, and an end state on the .slide-left-enter-active and .slide-left-leave-active classes. That part is working fine.

The problem is that sometimes there can be a delay of several milliseconds between when the animation is triggered on the "enter" element and on the "leave" element. This is because it takes an unpredictable amount of time for the JS interpreter to get from one of the addClass calls to the other one. If you hit a garbage collection, for example, it could be a relatively long time.

This causes strange artifacts in our animations. See http://plnkr.co/A2z1mAQ0D6P6RJIX7fDJ for a small example.

We would like to propose a new animation type that could be added in addition to "enter" and "leave" for ngView and any other directives that might make sense. We think it could be called "change".

The idea for "change" is that it would add classes such as .slide-left-change and .slide-left-change-active directly on the ngView element. Then we could rewrite our CSS to be triggered on this class change instead.

For example, this CSS

.slide-left-enter {
    left: 100%;
    transition: 1s linear left;
}
.slide-left-enter.slide-left-enter-active {
    left: 0;
}

.slide-left-leave {
    left: 0;
    transition: 1s linear left;
}
.slide-left-leave.slide-left-leave-active {
    left: -100%;
}

would become

.slide-left-change .slide-left-enter {
    left: 100%;
    transition: 1s linear left;
}
.slide-left-change.slide-left-change-active .slide-left-enter {
    left: 0;
}

.slide-left-change .slide-left-leave {
    left: 0;
    transition: 1s linear left;
}
.slide-left-change.slide-left-change-active .slide-left-leave {
    left: -100%;
}

The idea is that now there is just one addClass call that triggers both animations at exactly the same moment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions