I would like to be able to flip infinitely an object in one direction or the other by clicking on a button. The animation is inspired by this example: http://www.vishmax.com/en/labs/css-vertical-flip-animation-code-with-demo/
The code: https://codesandbox.io/s/angular-wkbb5?fontsize=14
Here is my template:
<div class="outer">
<div class="front" [@frontFlipAnim]="flip">
<img src="http://vishmax.com/demos/images/front.png">
</div>
<div class="back" [@backFlipAnim]="flip">
<img src="http://vishmax.com/demos/images/back.png">
</div>
</div>
<button (click)="toggleFlip()">Flip</button>
My CSS:
.outer {
margin-left: 200px;
}
.outer div {
transition: all .6s;
position: absolute;
}
.outer div img {
width: 200px;
}
.front {
z-index: 999;
}
.back {
z-index: -999;
-webkit-transform: rotateX(180deg);
-moz-transform: rotateX(180deg);
-o-transform: rotateX(180deg);
-ms-transform: rotateX(180deg);
transform: rotateX(180deg);
}
and my component:
import { Component, OnInit } from '@angular/core';
import { trigger, style, state, transition, group, animate } from '@angular/animations';
@Component({
selector: 'flip',
templateUrl: './flip.component.html',
styleUrls: ['./flip.component.scss'],
animations: [
trigger('frontFlipAnim', [
state('up', style({
transform: 'rotateX(-180deg)',
zIndex: -999
})),
state('down', style({
transform: 'rotateX(0deg)',
zIndex: 999
})),
transition('up => down', animate('400ms ease-out')),
transition('down => up', animate('400ms ease-in'))
]),
trigger('backFlipAnim', [
state('up', style({
transform: 'rotateX(0deg)',
zIndex: 999
})),
state('down', style({
transform: 'rotateX(180deg)',
zIndex: -999
})),
transition('up => down', animate('400ms ease-out')),
transition('down => up', animate('400ms ease-in'))
])
]
})
export class FlipComponent implements OnInit {
flip: string;
constructor() {
this.flip = 'up';
}
ngOnInit() {
}
toggleFlip() {
this.flip = (this.flip === 'up') ? 'down' : 'up';
}
}
In this example, I can only flip up and down but never flip up infinitely or flip down infinitely like a flip counter.