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

Weird behavior of $animateCss with ng-if and quick toggling of elements in 1.4.0rc1 #11723

Closed
Rush opened this issue Apr 25, 2015 · 4 comments
Closed

Comments

@Rush
Copy link

Rush commented Apr 25, 2015

Angular version 1.4.0rc1

Old

I wrote a custom javascript animation and applied it to ng-if:

mod.animation('.slide-margin', function($animateCss) {
    var animation = {
      enter : function(element, done) {
        var height = element[0].offsetHeight;
        var animator = $animateCss(element, {
          from: {
            marginTop: '-' + height + 'px'
          },
          to: {
            marginTop: '0px'
          },
          duration: 0.5
        });
        animator.start().finally(done);
      },
      leave : function(element, done) {
        var height = element[0].offsetHeight;
        var animator = $animateCss(element, {
          from: {
          },
          to: {
            marginTop: '-' + height + 'px'
          },
          duration: 0.3
        });
        animator.start().finally(done);
      },
      move : function(element, done) {
      },
      addClass : function(element, className, done) {
      },
      removeClass : function(element, className, done) {
      }
    };
    return animation;
  });
a(ng-click='show=!show') CLICK
br
br
div.slide-margin(ng-if='show')
  p A
  p B
  p C

Simple behavior is correct when you toggle an item, it slides down and if you click again in the middle of the animation it slides back from the same position. But if you click yet again for it mid-animation to slide down ng-if creates a new DOM content and weirdly enough old DOM content starts animating down along with the new content. Is this expected behavior? Do you know of a workaround?

@Rush Rush changed the title Weird behavior of $animateCss with ng-if and quick toggling of elements Weird behavior of $animateCss with ng-if and quick toggling of elements in 1.4.0rc1 Apr 25, 2015
@Rush
Copy link
Author

Rush commented Apr 25, 2015

JSFiddle showing the problem http://jsfiddle.net/z8gtkpzd/ - spam-click on the CLICK

@Narretz
Copy link
Contributor

Narretz commented Apr 27, 2015

Did this work in 1.3.x?

@Narretz Narretz added this to the 1.4.x - jaracimrman-existence milestone Apr 27, 2015
@Rush
Copy link
Author

Rush commented Apr 27, 2015

There is no $animateCss in 1.3.x so as such this exact thing cannot be done in 1.3.x.

@matsko matsko modified the milestones: 1.4.0-rc.2, 1.4.x - jaracimrman-existence May 5, 2015
matsko added a commit to matsko/angular.js that referenced this issue May 5, 2015
matsko added a commit to matsko/angular.js that referenced this issue May 5, 2015
…ion is closed

In the post-quiet animation detection phase of $animateCss there is a
call to getComputedStyle which is cached, however, the cache is not
cleared until the next animation is run. This causes a caching issue
since the next animation's cache data may be read and provided
incorrectly. This patch clears the cache after each animation has
closed itself.

Closes angular#11723
@matsko
Copy link
Contributor

matsko commented May 5, 2015

This was definitely a bug. Thank you for finding it. This PR will fix the issue:

#11805

Also note that there is another PR which makes using $animateCss much easier:

matsko@290fb4d

matsko added a commit to matsko/angular.js that referenced this issue May 5, 2015
…ion is closed

In the post-quiet animation detection phase of $animateCss there is a
call to getComputedStyle which is cached, however, the cache is not
cleared until the next animation is run. This causes a caching issue
since the next animation's cache data may be read and provided
incorrectly. This patch clears the cache after each animation has
closed itself.

Closes angular#11723
matsko added a commit to matsko/angular.js that referenced this issue May 11, 2015
matsko added a commit to matsko/angular.js that referenced this issue May 22, 2015
@matsko matsko closed this as completed in e0e1b52 May 23, 2015
netman92 pushed a commit to netman92/angular.js that referenced this issue Aug 8, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.