简体   繁体   English

getComputedStyle(element).getPropertyValue(“--varName”) 在 firefox 中不起作用

[英]getComputedStyle(element).getPropertyValue(“--varName”) does not work in firefox

Well, I want to use some css vars in my js code.好吧,我想在我的 js 代码中使用一些 css 变量。

Here is the part of my.css file and the.js code:这是my.css文件和.js代码的一部分:

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

The problem is that in chrome, safari and the new Edge I'm getting right the color value in my constant, but in firefox, doesn't working.问题是在 chrome 中,safari 和新的 Edge 我在我的常量中得到正确的颜色值,但在 firefox 中,不起作用。

Any ideas?有任何想法吗? Thanks.谢谢。

It seems it was the version of firefox.似乎是 firefox 的版本。 It was the 68.xx Now with the 77.0.1 works fine.它是 68.xx 现在与 77.0.1 工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 window.getComputedStyle(element).getPropertyValue("order") 不返回 flexbox 元素的顺序? - Why does window.getComputedStyle(element).getPropertyValue("order") doesn't returns order of a flexbox element? Window.getComputedStyle在Firefox中未实现界面元素错误 - Window.getComputedStyle does not implement interface Element error in Firefox 当在 em 中设置元素的 fontSize 时,getComputedStyle(elem,).getPropertyValue('font-size') 返回错误值 - getComputedStyle(elem,).getPropertyValue('font-size') is returning wrong value when element's fontSize is set in em Firefox getComputedStyle返回“自动” - Firefox getComputedStyle returns “auto” IE和Firefox中的getComputedStyle()和cssText - getComputedStyle() and cssText in IE and Firefox selectedIndex在firefox中不起作用,来自以下数组元素 - selectedIndex does not work in firefox, from an array element that is Window.getComputedStyle的参数1未实现接口Element - Argument 1 of Window.getComputedStyle does not implement interface Element 为什么对于父级隐藏的元素,getComputedStyle不返回display:none? - Why does getComputedStyle not return display:none for an element hidden by a parent? 为什么 getComputedStyle() 方法在我的 Nuxt 应用程序中无法正常工作? - Why getComputedStyle() method does not work properly in my Nuxt app? element.style或window.getComputedStyle()不显示float - element.style or window.getComputedStyle() does not showing float
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM