如何获取样式表中设置的CSS变量值?

时间:2018-09-05 09:30:28

标签: javascript css css-variables

我有这个CSS:

body {
    --animation: terminal-bar;
    --size: 1.4;
}

如何在JavaScript中获得--animation的值?

我已经尝试过了:

getComputedStyle(document.body)['--animation'];
document.body.style.getPropertyValue('--animation');

它们都不起作用,我已经在开发人员工具中找到了它:

document.body.computedStyleMap().get('--animation')[0]

但根据MDN,仅在Chrome中支持。

是否有相对的跨浏览器解决方案(它不需要在IE中工作),您可以在css样式表中获得css变量集的值?

0 个答案:

没有答案