[英]How can I utilize my custom theme's colors in a component's animation?
I have a component that animates on enter and leave. 我有一个在进入和离开时动画的组件。 One of these transitions changes the background color to the primary color, but I currently have it hard-coded.
这些转换之一将背景色更改为原色,但目前我已对其进行了硬编码。
animations: [
trigger('fadeInOut', [
state('in', style({ opacity: 1, background: 'transparent' })),
transition(':enter', [
style({
background: '#1976d2' // Primary theme color
}),
animate('0.5s ease-in-out')
]),
transition(':leave', [
animate('0.3s ease-out', style({ opacity: 0 }))
])
])
]
I'd like to avoid hard-coding the color and instead do something like this 我想避免对颜色进行硬编码,而是这样做
background: 'primary'
or 要么
background: MyTheme.colors.primary
What's the proper convention here? 这里合适的约定是什么? Do I need to just set the element's background color in the component's css (or, in this case, scss) to the animation color and just animate it away instantly?
我是否需要将组件的CSS(或在本例中为Scss)中的元素背景颜色设置为动画颜色,并立即对其进行动画处理? I'm worried that would degrade horribly, especially if I later decide to put in a toggle for animations or something.
我担心这会严重恶化,尤其是如果我后来决定为动画或其他内容设置切换开关时。
create 2 classes in your SCSS/CSS... use [ngClass] to change the applied class to your component. 在您的SCSS / CSS中创建2个类...使用[ngClass]将应用的类更改为您的组件。
similar question was asked earlier too: Bootstrap 4 dark & light mode switch 前面也问过类似的问题: Bootstrap 4暗光模式开关
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.