Im working on a personal project where I have a number of cards and would like to spin through them vertically multiple times and end up on a random card. I'm recreating my project in angular2 and am a little lost on how I would animate the spinning. This is what I have so far...
card.component.ts:
@Component({
selector: 'app-card',
styleUrls: ['./card.component.css'],
templateUrl: './card.component.html',
animations: [
trigger('spinCard', [
state('inactive', style({
transform: 'translateY(0px)'
})),
state('active', style({
transform: 'translateY(100%)'
})),
transition('inactive => active', animate('200ms ease-in-out')),
transition('active => inactive', animate('200ms ease-in-out'))
])
]
})
export class CardComponent {
@Input()
cardState: string;
}
card.component.html:
<div class="card {{cardStyle}}" [@spinCard]="cardState">
<div class="inside-text" id="{{cardId}}">{{cardName}}</div>
</div>
spinner.component.html:
<div class="spinner" id="spinner">
<div class="game-container">
<div class="game-overlay"></div>
<div class="game-area" id="game-area">
<app-card *ngFor="let card of (cards | spinnablePipe: true)" cardState={{cardState}} cardName={{card.name}} cardId={{cardId}} cardStyle={{cardStyle}}></app-card>
</div>
</div>
<div class="spin-layout">
<button type="button" class="spin-btn green-btn" aria-label="Spin" (click)="animateSpin()">
<span>S P I N</span>
</button>
</div>
In native JS, I simply requestAnimationFrame() and change the css and html through JS. However I'm not too sure how to do this the Angular-way.
I'd like to be able to hit a button, the cards would spin within a container and the cards would come to a stop on a random card.
My best idea so far was just to add 5ish sets of identical cards to the container and animate those. I don't think this is a correct approach tho, and also I'm not sure how I would randomize where they'd stop.
Would love some help! Thanks!
try following example for spinning cards
app.component.html
app.component.scss
app.component.ts