css中setProperty()方法记录

254 阅读1分钟

语法:

style.setProperty(propertyName, value, priority)

// propertyName 代表被更改CSS属性;
// value 新的属性值,未指定,则空字符串;
// priority 允许设置 “important” CSS优先级,未指定,则空字符串;

示例

// 1.调用它需要js对象
document.documentElement.style.setProperty("--body-font-color", "#1b1e21")

// 2.起名时,css中要用var()函数取值,名字必须以"–"开头;
.box{ 
    background-color: var(--body-font-color) !important; 
    transition: 2s linear; 
}

// 3.可任意的dom对象