[英]animate with material theme colors
I got 2 themes with angular material (light & dark) and want to leverage angular animations in my component. 我有2个带有角度材质的主题(浅色和深色),并且想在组件中利用角度动画。 I was wondering if there was a way to get colors like 'accent' and 'primary' into the animations.
我想知道是否有办法将“重音”和“基色”等颜色添加到动画中。
Here's some code: 这是一些代码:
animations: [
trigger('ClickLike', [
state('idle', style({
opacity: 1,
color: 'primary'
})),
state('clicking', style({
opacity: 0.2,
color: 'accent'
})),
transition('idle => clicking', [
animate('200ms')
]),
transition('clicking => idle', [
animate('150ms')
])
])
]
Obviously, this isn't working, because there's no 'accent' or 'primary'. 显然,这是行不通的,因为没有“口音”或“主要”字样。 I know I can just use css classes in combination with [ngClass] to get the same animation, but like I said I want to do it in angular.
我知道我可以将CSS类与[ngClass]结合使用来获得相同的动画,但是就像我说的那样,我想按角度进行。
Tricky, but you can. 棘手的,但是可以。
First, you have to get the Material color of your themes. 首先,您必须获取主题的“材质”颜色。
Create a simple component and set its color. 创建一个简单的组件并设置其颜色。
<button #matColorRefBtn color="primary" mat-raised-button [style.display]="'none'"></button>
Now, you can use the reference in an animation param : 现在,您可以在动画参数中使用参考:
<div [@ClickLike]="{ value: yourValueForTheAnimation, params: {primaryColor: matColorRefBtn.style.backgroundColor }}"></div>
Now, you can use the param in your animation : 现在,您可以在动画中使用参数:
animations: [
trigger('ClickLike', [
state('idle', style({
opacity: 1,
color: '{{ primaryColor }}'
})),
...
])
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.