【问题标题】:getComputedStyle(element).getPropertyValue("--varName") does not work in firefoxgetComputedStyle(element).getPropertyValue("--varName") 在 Firefox 中不起作用
【发布时间】:2020-06-17 08:20:07
【问题描述】:

嗯,我想在我的 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 中却不起作用。

有什么想法吗? 谢谢。

【问题讨论】:

  • "在 chrome、firefox 和新的 Edge 中我做对了...,但在 firefox 中不起作用"您的代码最终在哪个浏览器中“运行”不工作”? (代码似乎可以在 FF77 中正常工作。)
  • 对不起,我拼错了。在 chrome、safari 和 new edge 中工作。在 Firefox 中它没有。

标签: javascript firefox getcomputedstyle getpropertyvalue


【解决方案1】:

好像是火狐的版本。这是 68.x.x 现在使用 77.0.1 可以正常工作。

【讨论】:

    猜你喜欢
    • 2015-10-08
    • 2021-07-21
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多