通过LESS和CSS动态(在运行时)更改变量? [英] Changing variable dynamically (at runtime) via LESS and CSS?
问题描述
@myThemeBackground = #ddd;
div#box1 { background: @myThemeBackground; }
我使用LESS为我的css使用变量。它工作正常,但我想知道是否有一种方法,我在运行时通过javascript或某事动态地更改myThemeBackground。
I'm using LESS in order to use variables for my css. It works fine, but I'm wondering if there's a way for me to change the "myThemeBackground" dynamically at runtime via javascript or something.
所以说,如果用户选择一个自定义颜色的背景我想让整个皮肤改变。
So say if the user chooses a custom color for the background I'd like the entire skin to change.
注意:这是为动态主题/皮肤的应用程序,用户选择的颜色背景为例,然后整个应用程序更改(无需刷新页面)
Note: this is for dynamically theming/skinning an application where the user chooses the color for the background for example and then the whole app changes (without a page refresh)
推荐答案
modifyVars方法:
You can modify Less variables on the fly using the modifyVars method:
less.modifyVars({ myThemeBackground : '#000' });
这篇关于通过LESS和CSS动态(在运行时)更改变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!