How to control Sass Variable with javascript

2020-01-29 08:32发布

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 JavaScript.

For example, in style.sass we have

$bg : #000;
$font-size: 12px;

How can I change these values from JavaScript?

7条回答
Emotional °昔
2楼-- · 2020-01-29 09:07

JavaScript runs client-side (in the web browser), while Sass is generated server-side, so you have to find some way to bridge the gap 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.

查看更多
登录 后发表回答