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

$animate.addClass difficulties and / or glitches #5620

Closed
caitp opened this issue Jan 3, 2014 · 5 comments
Closed

$animate.addClass difficulties and / or glitches #5620

caitp opened this issue Jan 3, 2014 · 5 comments

Comments

@caitp
Copy link
Contributor

caitp commented Jan 3, 2014

http://plnkr.co/edit/CGgL13QsEwnwv9D1shG1?p=preview is an example of the reason for this --- it's very hard to have different animations for the showing and hiding of the content, and causes some glitches.

For my use case, I don't want to remove nodes from the DOM, so ng-switch or ng-if are not really applicable (it's important, otherwise I end up losing playback position of media content).

If there's a way to get the $animate.addClass behaviour to behave similarly to $animate.enter/leave, that would be great.

I'm not totally sure where to poke at that though, and it's entirely possible that I'm getting this wrong due to not being a CSS guru. But if there is a good way to do this for addClass, it should probably be included in the documentation.

Let me know if I'm being a complete idiot here :> This issue probably only really applies to ngShow/Hide, due to their use of the ng-hide class which seems to cause this issue.

@IgorMinar
Copy link
Contributor

@matsko can you please take a look?

@matsko
Copy link
Contributor

matsko commented Jan 4, 2014

Fixing #5588 first since it introduced three strange bugs with ngShow/ngHide and $animate. It might put a dent into this one when fixed. Almost done with that one.

@matsko
Copy link
Contributor

matsko commented Jan 4, 2014

Here's the working version of your code -- without a flicker: http://plnkr.co/edit/IHrPITen0MGijczkx7vL?p=preview. I agree that the ngShow/ngHide restrictions do make things difficult. Let's resume once the other issue out of the way.

@caitp
Copy link
Contributor Author

caitp commented Jan 4, 2014

ahh, I had tried many different combinations, I guess I missed that one. Might be useful to show an example of this in the ngShowHide docs

@matsko
Copy link
Contributor

matsko commented Jan 6, 2014

Just fixed #5588. It doesn't fix or relate to your issue. But your CSS code for the original example is incorrect. Let me explain why.

when the page loads

  • Your element starts off with a .slide on the element which has no transition styling.
  • The element is hidden and therefore has .ng-hide on it. No animations are run on start up.

when the show animation runs

  • The ngShow expression changed and then it triggers the .ng-hide-remove animation.
  • .ng-animate is applied to the element and then $animate detects that it has some transitions on it.
  • Animate adds .ng-hide-remove and waits 10ms for the reflow to kick in. The CSS classes at this time on the element are .slide .ng-animate .ng-hide-remove .ng-hide, but since you defined that .ng-animate.ng-hide sets display:block then the element shows up for 10ms (the flicker effect).
  • Then, after the 10ms gap, .ng-hide-remove-active is applied and .ng-hide is removed. It then waits 666ms to animate the element from the translate style of 9999px to ???? (nothing since the translate style doesn't change). After 666ms (actually after the 999ms timeout that ngAnimate sets to close off all animations) then the .ng-hide-remove and .ng-hide-remove-active classes are removed and then the actual animation kicks in to remove the 9999px translate which brings it back to the center of the screen.

when the hide animation runs

  • This works fine.

So just an incorrect use of the classes. I agree that the class-based animations are complicated to use and should be much better documented. They could also be changed around in 1.3 or 2.0, but the docs are more important at the moment.

Closing this issue.

@matsko matsko closed this as completed Jan 6, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants