Change a single variable with less.js

I am trying to use less.js to make modifications to a less stylesheet for demonstration purposes. What I would like it to do is remember previous changes so I only have to send a single change each time for efficiency. Let's say I have the following:

@PrimaryColor: #FFF;
@SecondaryColor: #000;

If I change one parameter, it works fine.

less.modifyVars({ "@PrimaryColor": "#ff0000" });

The colors now look like this:

@PrimaryColor: #ff0000;
@SecondaryColor: #000;

Now if I call the method again:

less.modifyVars({ "@SecondaryColor": "#00ff00" });

The primary color switches back and the secondary color changes:

@PrimaryColor: #FFF;
@SecondaryColor: #00ff00;

My question is whether there is a way or a method that will just change the one parameter and leave the other changes alone?


Quick look at the source code of modifyVars seems to confirm that you can't do it.

It looks like the source .less file is recompiled every time you call modifyVars and only those changes that you passed in the last modifyVars call are applied.

链接地址: http://www.djcxy.com/p/96210.html

上一篇: 阴影不执行过渡

下一篇: 使用less.js更改单个变量