javascript - 如何修复 TypeError : window. getComputedStyle(...) 在 Firefox 中为空?

标签 javascript jquery html

我正在使用 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/

相关文章:

javascript - Firebase 中的递归错误太多

javascript - 如何以 Angular 访问另一个 View 的 $scope?

javascript - 将鼠标悬停在一个 div 上时更改其他 div 的类

javascript - 返回参数显示对象Object

javascript - 推送到轻量级 HTML5 客户端的 ZeroMQ 套接字

javascript - 如何在 JavaScript 刺激中导入 npm 模块

jquery - 使用 ASP.NET MVC 在 JS 文件中设置 jQuery 的 ajax url

javascript - 为什么我的 div 元素不直接位于彼此之上?

html - 如何在伪元素上包含 $ 字符

javascript - 更改谷歌地图标记的图标