项目是采用scss进行的样式设定,通过设定css变量名的方式可以实现网站运行时的颜色整体切换。
示例:
:root {
--my-color: #999999;
}
.demo{
$myColor: var(--my-color, #888888)
}
两个参数:property,value
var(--my-color, #888888)
会先查找css变量--my-color,若存在则使用该变量的值,若不存在则$myColor的值会是#888888
//获取
getComputedStyle(document.documentElement).getPropertyValue(‘--my-color‘)
//设置
document.documentElement.style.setProperty(‘--my-color‘, ‘pink‘)
原文:https://www.cnblogs.com/asahi-front/p/14945412.html