1

Im trying to trigger animation when the value of countAllOrders changes. Specifically, im trying to set the margin of list using keyframs in angular animation. My html is as follows:

  <ul class="digits" [@ordersValue]="countAllOrders" #digits>
    <li>0</li>
    <li>1</li>
    <li>{{ countAllOrders }}</li>
  </ul>

and the animation implementtation is:

  animations: [
    trigger('ordersValue', [
      transition(':increment', [
        animate('1s', keyframes([style({ marginTop: '-7em' })])),
      ]),
    ]),
  ],

the initial css of .digits sets margin-top:0em . during animation the desired effect works but instead of finishig with margin top's value to be -7em it ends with 0em. According to some answers I found here I tried to use state

trigger('ordersValue', [
  state(':increment', style({ marginTop: '-7em' })),
  transition(':increment', [
    style({ marginTop: '-7em' }),
    animate('1s', style('*')),
  ]),
]),

css:

.digits {
  list-style-type: none;
  margin-top: 0em;
  animation-duration: 1s;
  animation-timing-function: ease;
  animation-fill-mode: forwards;
}

but that didnt help, any idea how to tackle this one?

Andrew Halil
  • 1,195
  • 15
  • 15
  • 21
yariv bar
  • 936
  • 3
  • 20
  • 39

1 Answers1

0

I'm not sure if in the keyframe you need to have a from marginTop: '0' and to marginTop: '-7em'?

Here is a link which might help : https://www.w3schools.com/cssref/css3_pr_animation-keyframes.asp

Just add the last line animation-fill-mode:forwards; and remove the infinite at the end of the second last line.

  position: relative;
  animation: mymove 5s;
  animation-fill-mode:forwards;
John
  • 46
  • 4