【发布时间】:2018-09-10 22:43:20
【问题描述】:
我正在学习 Angular,但偶然发现了这个我无法解决的小问题。
我设法为 div 设置了动画(如小吃店),但 div 中的文本没有像背景层那样平滑地出现或消失。
import { Component } from '@angular/core';
import { MyService } from './myService';
import { trigger, state, style, transition, animate } from '@angular/animations';
@Component({
selector: 'snackbar',
templateUrl: './snackbar.component.html',
styleUrls: ['./snackbar.scss'],
animations: [
trigger('shrinkOut', [
state('inactive', style({height: '*'})),
transition('* => void', [
style({ height: '*'}),
animate(300, style({height: 0}))
]),
transition('void => *', [
style({ height: 0}),
animate(300, style({height: '*'}))
]),
]
)
]
})
export class SnackbarComponent {
constructor(
public myService: MyService,
) { }
}
div.snackbar {
position: absolute;
width: 100%;
height: 40px;
top: 0;
left: 0;
z-index: 1000;
text-align: center;
vertical-align: middle;
line-height: 40px;
}
div.snackbar.success {
background-color: #9f5a77;
}
div.snackbar.error {
background-color: #f44336;
}
<div class="snackbar {{myService.currentService.type}}" *ngIf="myService.currentService" [@shrinkOut]>
Some Text
</div>
关于如何将文本与背景图层同步有什么想法吗?
【问题讨论】:
标签: javascript css angular animation