How to control Sass Variable with javascript

前端 未结 8 1599
予麋鹿
予麋鹿 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:52

    CSS

    :root {
      subTitleLeftMargin: 1.5vw;
    }
    
    .element {
      margin-left: var(--subTitleLeftMargin);
    }
    

    JS or TS

    document.documentElement.style.setProperty("--subTitleLeftMargin", "6vw");
    
    0 讨论(0)
  • 2020-12-01 18:52

    JavaScript runs client-side (in the web browser), while Sass is generated server-side, so you have to find some way to bridge that gap. One way to do this would be to set up some AJAX-style listening to send JavaScript events over to your server, and then have the server edit and re-compile your style.sass file.

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