I m trying to animate a list which is made with ngFor. When dynamically a new item is added to the array, i want to have the animation bellow. Somehow i cant get this rolling effect. Any ideas what am i doing wrong ?
@Component({
selector: 'widget',
templateUrl: './widget.component.html',
styleUrls: ['./widget.component.scss'],
animations: [
trigger('slideInOut', [
transition(':enter', [
style({transform: 'translateY(-100%)'}),
animate('800ms ease-in-out', style({transform: 'translateY(0%)'}))
])
])
]
})
html
<div *ngFor="let winner of widgetService.winners; let i = index"
class="winners__item" [@slideInOut]>
<img [src]="winner.imageUrl" alt="{{ winner.gameName }}">
<div class="block__container--first">
<div class="block__container--first--gameName">{{winner.gameName}}</div>
<div class="block__container--first--firstName">{{winner.firstName}}</div>
</div>
<div class="block__container--second">
<div class="block__container--second--timestamp">{{winner.timestamp}}m ago</div>
<div class="block__container--second--winning">{{winner.amount}} €</div>
</div>
</div>
[![enter image description here][1]][1]
what i have:
[![enter image description here][2]][2]
what i tried:
animations: [
trigger('slideInOut', [
transition(':enter', [
style({marginTop: '-100px'}),
animate('800ms ease-in-out', style({transform: 'translateY(0%)'}))
])
])
]
transitionhas no impact to the actual space that the new item takes. You could give the new item a negative top margin, so the item is actually above the list, and pushes the following items down. So instead oftransform: 'translateY(-100%)'usemargin-top: '-100%'.margin-top: '0px'inanimate()as well