How to control Sass Variable with javascript

前端 未结 8 1625
予麋鹿
予麋鹿 2020-12-01 17:47

I have a Sass file which is generating a CSS file. I have used many variables in my sass file for background color, font-size, now I want to control my all variables through

8条回答
  •  春和景丽
    2020-12-01 18:34

    I also needed this functionality, here's what worked for me:

    With JS you can set a class to body, ex. .blue or .default Now create a set of rules to extend from, which you'd like to set:

    .default .themeColor {
      color: 'red';
    }
    .blue .themeColor {
      color: 'blue';
    }
    

    Now instead of having color: $someColor in your scss file, use it like this:

    .someClass {
       @extend .themeColor;
     }
    

    Now, if your body will have the default class, the color inside someClass will be red, and if body will have the blue class the color will be blue.

提交回复
热议问题