我正在使用 zepto 进行拖动和交换,它在 chrome 中完美运行,但在 firefox 中显示错误。下面是显示错误的 dragswap 脚本部分。请帮忙。提前致谢
`; (function ($) {
$.fn.dragswap = function (options) {
var dragSrcEl;
function getPrefix() {
var el = document.createElement('p'),
getPre, transforms = {
'webkitAnimation': '-webkit-animation',
'OAnimation': '-o-animation',
'msAnimation': '-ms-animation',
'MozAnimation': '-moz-animation',
'animation': 'animation'
};
document.body.insertBefore(el, null);
for (var t in transforms) {
if (el.style[t] !== undefined) {
el.style[t] = "translate3d(1px,1px,1px)";
// if(window.getComputedStyle && (style = window.getComputedStyle(element, null)) !== null)
getPre = window.getComputedStyle(el).getPropertyValue(transforms[t]);
// return the successful prefix
return t;
}
}
document.body.removeChild(el);
}
最佳答案
Firefox 有一个错误,如果元素是 "display: none"
,则 window.getComputedStyles
将返回 null
。
下面是我找到修复第三方代码错误的知识的地方。注意在我的例子中,元素也是一个 iFrame https://github.com/marcj/css-element-queries/issues/148
关于javascript - 如何修复 TypeError : window. getComputedStyle(...) 在 Firefox 中为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46127213/