简体   繁体   English

如何在组件的动画中利用自定义主题的颜色?

[英]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.

相关问题 如何将材质主题颜色用于自定义内容? - How can I use Material Theme colors for custom things? 如何在node_modules主题文件外使用自定义材质颜色? - How can I use custom material colors outside the node_modules theme file? 为什么我的自定义 colors 在我的 Angular 材料主题中不起作用? - Why My custom colors are not working in my Angular material theme? 如何访问或检查超级父级组件中子组件的模板驱动表单的验证 - How can I access or check validation of the child component's template driven form in the super parent's component 如何获得 Angular 5 组件元素的位置? - How can I get an Angular 5 component element's position? 如何获得组件方法的真实姓名? - How can I get component's method real name? 角度2:如何在该组件内访问自定义组件的FormControl实例? - Angular 2: How do I access a custom Component's FormControl instance within that Component? 如何使Angular 6组件继承其扩展组件的样式? - How do I get my Angular 6 components to inherit it's extended component's styles? 不使用Material的调色板颜色创建Angular主题 - Create Angular Theme without using Material's palette colors 访问在组件的 scss 中定义的自定义主题的原色 - Accessing primary color which is defined custom theme inside component's scss
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM