从 JavaScript 检索或设置 LESS 变量?
在测试我的网络应用程序时,我希望能够使用简单的下拉菜单设置我的 LESS @variables 之一的值。 (完全改变配色方案)。
我想设置该值后,LESS 必须使用新值重新加载/重新编译 .less 文件?
有什么简单的方法可以实现这一点吗? (我没有运行node.js)
基本示例如下:
styles.less
@base-color = `window.baseColor()`
While testing my web app, I'd like to be able to set the value of one of my LESS @variables using a simple dropdown. (To change the color scheme altogether).
I guess after setting the value, LESS has to reload/recompile the .less files with the new value?
Is there any simple way of accomplishing this? (I'm not running node.js)
The basic example would be something like:
styles.less
@base-color = `window.baseColor()`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你这样做的方式有点太复杂了;)
这是我的建议:
在你的 body 标签上设置一个类:
在你的 .less 文件中定义你的主题:
使用 jQuery(或者只是普通的 JS)在下拉状态改变时改变 body 标签的类。
这就是我要做的(并用一些漂亮的小部件替换下拉列表;)
干杯
I think you're doing it in a bit too complicated way ;)
Here's what I propose:
Set a class on your body tag:
In your .less file define your themes:
Using jQuery (or just plain JS) change the class of the body tag upon dropdown state change.
That's how I'd do it (and replace the dropdown with some nice widget ;)
Cheers