LESS - set variables on the client side

微笑、不失礼 提交于 2019-11-29 17:30:49

I do not know if the parser takes any arguments, but why would you refuse to use the built-in javascript evaluation, e.g. adding something like:

@layoutwidth: `document.getElementById("inputLayoutWidth") + "px"`;

to your Less-Stylesheet. Or, using jQuery, as you proposed:

@layoutwidth: `$("#inputLayoutWidth").val() + "px"`;

while using an input field like

<input type="text" id="inputLayoutWidth" value="720" />

and invoke parsing each time the input field is changed.

If you are using 3.x version of less CSS than u can set them in javascript code as well.

 less.modifyVars({
   '@buttonFace': '#5B83AD',
   '@buttonText': '#D9EEF2'
});

I don't know if this method is also present in older version of less.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!