Retrieve or set LESS variable from JavaScript?

后端 未结 1 650
刺人心
刺人心 2021-01-20 00:47

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 gue

相关标签:
1条回答
  • 2021-01-20 01:06

    I think you're doing it in a bit too complicated way ;)

    Here's what I propose:

    1. Set a class on your body tag:

      <body class='theme_default'></body>
      
    2. In your .less file define your themes:

      body.theme_default { base_color: #fff; }
      body.theme_gray    { base_color: #ccc; }
      etc..
      
    3. 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

    0 讨论(0)
提交回复
热议问题