javascript 如何修复 Window.getComputedStyle 不是对象错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21899272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix Window.getComputedStyle is not an object error
提问by Nomi
I am trying to use draggabilly available at https://github.com/desandro/draggabilly
我想在使用draggabilly可用 https://github.com/desandro/draggabilly
it works fine in html. Now when i have tried to add it in wordpress. I am getting following error in firebug console.
它在 html 中工作正常。现在,当我尝试在 wordpress 中添加它时。我在萤火虫控制台中收到以下错误。
TypeError: Argument 1 of Window.getComputedStyle is not an object.
return s.getComputedStyle(t, null)
here is a link for js file http://draggabilly.desandro.com/draggabilly.pkgd.min.js
这是 js 文件的链接 http://draggabilly.desandro.com/draggabilly.pkgd.min.js
回答by Samuel Larcher
You are calling init twice. Go through your code and remove one instance.
您正在调用 init 两次。检查您的代码并删除一个实例。
回答by centurian
I received this error testing my project with IE8: finally it was so obvious, this method doen't work with IE 8!
我在用 IE8 测试我的项目时收到这个错误:最后很明显,这种方法不适用于 IE 8!
Error: Object doesn't support this property or method at: http://...
I received this error with FF that does support this method but I forgot to change window
to my frame window object!
我收到了支持此方法的 FF 的此错误,但我忘记更改window
为我的框架窗口对象!
console.log(getComputedStyle(window.document.querySelector('.tip > .tip.top'), ':after').getPropertyValue('left'));
TypeError: Argument 1 of Window.getComputedStyle is not an object.
at: http://...
Note that the above error pops up even if your window
object is ok but the querySelector
returns nothing! (I suspect it's your case).
请注意,即使您的window
对象querySelector
没问题,也会弹出上述错误,但没有返回任何内容!(我怀疑这是你的情况)。