【发布时间】:2017-10-10 15:07:44
【问题描述】:
我在 angular2+ 组件上使用了一些动画。 它工作正常,但我想使用一些变量而不是硬编码值('20px','10px')。
是否有可能在动画中使用一些打字稿变量?
例如:
@Component({
selector: 'animationDialog',
templateUrl: './animationDialog.component.html',
styleUrls: ['./modal.component.css'],
animations: [
trigger('dialog', [
state('enter', style({
transform: 'translate(this.TYPESCRIPTVAR1, this.TYPESCRIPTVAR2)',
top: 'this.TYPESCRIPTVAR3',
height: 'this.TYPESCRIPTVAR4'
})),
('leave', style({
transform: 'translate(this.TYPESCRIPTVAR1, this.TYPESCRIPTVAR2)',
top: 'this.TYPESCRIPTVAR3',
height: 'this.TYPESCRIPTVAR4'
}))
当前代码:
animations: [
trigger('dialog', [
state('enter', style({
transform: 'translate(0px, -80px)',
top: '200px',
height: '320px'
}))
我已经检查过另一个question,但这个问题只处理一种可变样式。就我而言,我在一个属性上具有可变样式(例如“背景颜色”),但这些属性在不同状态下是可变的。
谢谢。
【问题讨论】:
-
@zigzag 感谢您的帮助。在此链接中,它们只有一个属性作为变量。就我而言,所有属性都应该是 typescript-variables。
-
对,但我不明白为什么如果一个样式属性可以通过变量引用,它们都不应该。
-
我明白你的意思。例如,您有两种状态,并且在两种状态中都有一个背景颜色的变量值('背景颜色':'*')。当您在 HTML 标记上获得以下属性时,您会参考哪个状态:[style.background-color]="bgColor"。您是参考第一个、第二个或两个状态的背景颜色吗?
标签: angular animation typescript