首页 > 解决方案 > getComputedStyle(element).getPropertyValue("--varName") 在 Firefox 中不起作用

问题描述

好吧,我想在我的 js 代码中使用一些 css 变量。

这是我的 .css 文件和 .js 代码的一部分:

const root = document.querySelector(":root");
const msgColor = getComputedStyle(root).getPropertyValue("--msg-color");
console.log(msgColor);
:root {
  --msg-color: crimson;
  --msg-text: floralwhite;
}

问题是,在 chrome、safari 和新 Edge 中,我的常量中的颜色值是正确的,但在 Firefox 中,它不起作用。

有任何想法吗?谢谢。

标签: javascriptfirefoxgetcomputedstylegetpropertyvalue

解决方案


好像是firefox的版本。它是 68.xx 现在与 77.0.1 工作正常。


推荐阅读