0

I would like to apply a constant style to an element during this element's animation's transition. The problem is the default behavior of a transition animates the style as well. For example in this example the red background fades during the animation (it's animated as well):

animations: [
  trigger('animate', [
    state('true', style({ height: '10px' })),
    state('false', style({ height: '30px' })),
    transition('true<=>false', [
      style({ backgroundColor: 'red' }),
      animate('5s'),
    ]),
  ])
]

Here I would like to have the background be constantly red as the height of the element changes. Is there a way to achieve such an effect with Angular animations?

2 Answers 2

3

I have found a way to do this with CSS/Sass. You can achieve this effect by using a .ng-animating class selector in CSS.

For example if your animation is targeting a list which has a class .list, you can do:

.list.ng-animating {
  background-color: red;
}

or if nested in SCSS:

.list {
  &.ng-animating {
    background-color: red;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Why do you want to change the element style instead of adding a class to do that specific function? Add a class like:

.bg-red{
  background-color:red !important;
}

And then remove it when you don't need it anymore. The !important is to avoid whatever is in the style tag to overwrite it.

1 Comment

I would like the red background to only appear while the animation is transitioning between the two states. If I used a class like this, the background would be always red, instead of just during the transition. I also don't think it's possible to manipulate HTML classes from within Angular animations, but I could be wrong.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.