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

fix($animate): run CSS animations before JS animations to avoid style inheritance #6799

Closed
wants to merge 1 commit into from

Conversation

matsko
Copy link
Contributor

@matsko matsko commented Mar 21, 2014

If a JS animation is run before a CSS animation then the JS animation may end up writing style
data to the element. If any transition or animation style data is written then it may end up
being accidentally inherited into the CSS animation hanlder that ngAnimate uses. This may result
in an unexpected outcome due to the tweaks and hacks that the CSS handler places on the element.
If the CSS animation is run before the JS animation then, if there are no transitions on the style
attribute nor within the global CSS on the page then nothing will happen and the JS animation can
work as expected.

Closes #6675

@mary-poppins
Copy link

Matias is a machine.

@@ -721,6 +721,32 @@ describe("ngAnimate", function() {
})
});

it("should always perform the CSS animation before the JS animation", function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a reason in a comment?

something like:

// this order is important so that js animations can't change element style and confuse us
// when computing styles to figure out transition duration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise only you know why this test is here and even you might forget the reason in the future :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

/* The CSS animation handler must always be rendered before the other JS animation
   handlers. This is important since the CSS animation handler may place temporary
   styling on the HTML element before the reflow commences which in turn may override
   other transition or keyframe styles that any former JS animations may have placed
   on the element: https://github.com/angular/angular.js/issues/6675 */

@IgorMinar
Copy link
Contributor

otherwise lgtm

… inheritance

If a JS animation is run before a CSS animation then the JS animation may end up writing style
data to the element. If any transition or animation style data is written then it may end up
being accidentally inherited into the CSS animation hanlder that ngAnimate uses. This may result
in an unexpected outcome due to the tweaks and hacks that the CSS handler places on the element.
If the CSS animation is run before the JS animation then, if there are no transitions on the style
attribute nor within the global CSS on the page then nothing will happen and the JS animation can
work as expected.

Closes angular#6675
@matsko
Copy link
Contributor Author

matsko commented Mar 26, 2014

MERGED

@matsko
Copy link
Contributor Author

matsko commented Mar 26, 2014

Landed as 2317af6

@matsko matsko closed this Mar 26, 2014
@matsko matsko deleted the fix_js_animation branch March 26, 2014 16:12
@matsko
Copy link
Contributor Author

matsko commented Mar 26, 2014

And as 0e5106e for 1.2.x

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngAnimate breaks jquery.transit (and possibly other transform-based animations) under Chrome
4 participants