【发布时间】:2019-08-18 12:05:48
【问题描述】:
我正在尝试在 Angular 中制作翻转动画。单击时它应该翻转 Y 轴,然后再次单击时反向翻转 Y 轴。此外,它应该具有根据翻转状态显示的正面和背面内容。
从后到前的翻转让我很伤心。根据我的尝试,我会出现奇怪的行为。我能做的最好的事情是一个奇怪的翻转,它从与前后翻转相同的方向开始,然后在最后改变方向。 *耸耸肩*
请注意,如果您在动画完成之前单击它,它会按需要工作。如果您等待它完成动画,则它具有上述行为。
这是原型:https://angular-epkrtn.stackblitz.io
有人可以帮忙做从后到前的翻转吗?
从下面的链接复制代码
app.component.ts
import { Component } from '@angular/core';
import { trigger, transition, animate, style, keyframes, state } from '@angular/animations';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
animations: [
trigger('flip', [
state('front', style({
transform: 'rotateY(0deg)'
})),
state('back', style({
transform: 'rotateY(180deg)'
})),
transition('front => back', [
animate('1s 0s ease-out',
keyframes([
style({
transform: 'perspective(400px) rotateY(0deg)',
offset: 0
}),
style({
transform: 'perspective(400px) scale3d(1.5, 1.5, 1.5) rotateY(80deg)',
offset: 0.4
}),
style({
transform: 'perspective(400px) scale3d(1.5, 1.5, 1.5) rotateY(100deg)',
offset: 0.5
}),
style({
transform: 'perspective(400px) scale3d(0.95, 0.95, 0.95) rotateY(180deg)',
offset: 0.8
}),
style({
transform: 'perspective(400px) rotateY(180deg)',
offset: 1
})
]))
]),
transition('back => front', [
animate('1s 0s ease-in',
keyframes([
style({
transform: 'perspective(400px) rotateY(180deg)',
offset: 0
}),
style({
transform: 'perspective(400px) scale3d(1.5, 1.5, 1.5) rotateY(100deg)',
offset: 0.4
}),
style({
transform: 'perspective(400px) scale3d(1.5, 1.5, 1.5) rotateY(80deg)',
offset: 0.5
}),
style({
transform: 'perspective(400px) scale3d(0.95, 0.95, 0.95) rotateY(0deg)',
offset: 0.8
}),
style({
transform: 'perspective(400px) rotateY(0deg)',
offset: 1
})
]))
])
])
]
})
export class AppComponent {
flipState = 'front';
onFlipClick() {
if (this.flipState == 'front') {
this.flipState = 'back';
} else {
this.flipState = 'front';
}
}
}
app.component.html
<div (click)="onFlipClick()" class="flip-card">
<div [@flip]="flipState" class="flip-card-inner">
<div class="flip-card-front">
FRONT
</div>
<div class="flip-card-back">
BACK
</div>
</div>
</div>
app.component.css
.flip-card {
height: 200px;
width: 200px;
background-color: transparent;
margin-top: 250px;
margin-left: auto;
margin-right: auto;
}
.flip-card-inner {
position: relative;
height: 100%;
width: 100%;
transform-style: preserve-3d;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
}
.flip-card-inner > div {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.flip-card-front {
background-color: blue;
}
.flip-card-back {
transform: rotateY(180deg);
background-color: green;
}
【问题讨论】:
标签: angular css animation flip angular-animations