javascript - 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 中,它不起作用。
有任何想法吗?谢谢。
解决方案
好像是firefox的版本。它是 68.xx 现在与 77.0.1 工作正常。
推荐阅读
- javascript - 如何将jQuery数据返回到打字稿中的主类
- python - 如何使用 sklearn 训练算法对数据点进行加权
- facebook - 通过 Facebook GraphAPI 列出相册中的视频
- r - 使用过去的迭代矢量化移动窗口
- php - 当新的 WP_Query 在后循环中时出现错误 502
- styling - React 引导组件无法正常工作
- javascript - 从父级监听 WebView 中的 console.logs
- javascript - 如何通过 id 在对象数组中添加新值(不是新项目)
- python - 如何增加子图的大小并减少水平间距?
- xml - 尝试使用 Powershell 更改 XML 文件中的值