动态设置 :root 和 获取 :root 内容 , 获取 var() 内容

通过 document.querySelector(":root")获取内容

一、获取值

var root=document.querySelector(":root")
    //获取
var color= getComputedStyle(root).getPropertyValue("--color")
    console.log(color)

二、设置值

var root=document.querySelector(":root")
 
    
//设置
root.style.setProperty("--color","#f00")


版权声明:本文为weixin_41854372原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。