jQuery WebKit 问题与 event.layerX 和 event.layerY

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7825448/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:18:29  来源:igfitidea点击:

WebKit issues with event.layerX and event.layerY

jquerygoogle-chromewebkit

提问by PeeHaa

I just noticed that I get tons of deprecated warnings in the latest (canary) build of Chrome.

我刚刚注意到,在最新的(金丝雀)Chrome 版本中,我收到了大量已弃用的警告。

event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future.

event.layerX 和 event.layerY 在 WebKit 中被破坏和弃用。它们将在不久的将来从引擎中移除。

Looks like jQuery is screwing thing up.

看起来 jQuery 把事情搞砸了。

I'm using: jquery-1.6.1.min.js.

我正在使用:jquery-1.6.1.min.js

Would it help to upgrade to the latest jQuery version or isn't it fixed yet or is it a Chrome bug or is it something else.

升级到最新的 jQuery 版本是否有帮助,或者它是否尚未修复,或者是 Chrome 错误还是其他什么。

PS

聚苯乙烯

I cannot show you code because I think it's a general error, but I suspect the warnings get thrown when I try to access a jQuery object or when jQuery tries to access the layerX / layerY (well I'm pretty sure that's the case considering the error :P).

我无法向您展示代码,因为我认为这是一个一般错误,但我怀疑当我尝试访问 jQuery 对象或当 jQuery 尝试访问 layerX / layerY 时会抛出警告(好吧,我很确定考虑到这种情况)错误:P)。

jQuery probably copies those properties into the jQuery object.

jQuery 可能会将这些属性复制到 jQuery 对象中。

So...

所以...

What's going on?

这是怎么回事?

EDIT

编辑

jQuery 1.7 is out and fixes this issue.

jQuery 1.7 已经发布并修复了这个问题。

Read more at their blog, here.

在他们的博客上阅读更多内容,请点击此处

采纳答案by Adam A

What's going on!?

这是怎么回事!?

"jQuery probably copies those properties into the jQuery object." You're exactly correct, so it sounds like you already know! :)

“jQuery 可能会将这些属性复制到 jQuery 对象中。” 你完全正确,所以听起来你已经知道了!:)

Hopefully jQuery will update their code to stop touching that, but at the same time WebKit should have known better than to log a deprecation warning on an event (at least in my opinion). One mousemove handler and your console explodes. :)

希望 jQuery 将更新他们的代码以停止触及它,但与此同时,WebKit 应该知道最好不要在事件上记录弃用警告(至少在我看来)。一个 mousemove 处理程序和您的控制台爆炸。:)

Here's a recent jQuery ticket: http://bugs.jquery.com/ticket/10531

这是最近的 jQuery 票证:http: //bugs.jquery.com/ticket/10531

UPDATE: This is fixed now if you upgrade to jQuery 1.7.

更新:如果您升级到 jQuery 1.7,现在已修复此问题。

Please note that if upgrading jQuery doesn't fix the issue for you it may have something to do with used extensions / plugins as Jake stated in his answer.

请注意,如果升级 jQuery 不能为您解决问题,则可能与 Jake 在他的回答中所说的使用的扩展/插件有关。

回答by David Murdoch

http://jsperf.com/removing-event-props/2

http://jsperf.com/removing-event-props/2

The temporary fix is to run this code before you do any event binding via jQuery:

临时修复是在通过 jQuery 执行任何事件绑定之前运行此代码:

(function(){
    // remove layerX and layerY
    var all = $.event.props,
        len = all.length,
        res = [];
    while (len--) {
      var el = all[len];
      if (el != 'layerX' && el != 'layerY') res.push(el);
    }
    $.event.props = res;
}());

UPDATE

更新

See the latest performance teststo find out what the fastest way is to remove the event props.

查看最新的性能测试,找出删除事件道具的最快方法。

回答by mekwall

The shortest solution to this is this one-liner:

最短的解决方案是这个单行:

$.event.props = $.event.props.join('|').replace('layerX|layerY|', '').split('|');

回答by t?rzsmókus

The enormous amount of these messages (I just got 80000 of them while using gmail)is indeed a bug in Chrome.

大量的这些消息(我在使用 gmail 时只收到了 80000 条)确实是 Chrome 中的一个错误。

You should star the issue on Chromium.

你应该在 Chromium 上为这个问题加注星标。

回答by Jake

It can also be caused by Chrome extensions, so check them if the jQuery update doesn't work.

它也可能是由 Chrome 扩展程序引起的,因此如果 jQuery 更新不起作用,请检查它们。

回答by DUzun

Here is another one line fix, without replacing the original instance of $.event.props (which may or may not be an array), just in case :-)

这是另一行修复,不替换 $.event.props 的原始实例(可能是也可能不是数组),以防万一:-)

$.each(["layerX","layerY"], function(i,v) { if((i=p.indexOf(v)) > -1) $.fn.splice.call($.event.props,i,1) })

回答by jca258

I've used this after calling any event:

我在调用任何事件后使用了它:

$.event.props.splice($.event.props.indexOf("layerY"),1);
$.event.props.splice($.event.props.indexOf("layerX"),1);

That worked for me, I have no warning messages since I've made this patch on my code.

这对我有用,因为我在我的代码上做了这个补丁,所以我没有警告消息。

回答by xgretsch

As well as the configuration issues listed in the other answers, this error can be triggered by a simple error in your own code: forgetting the '#' in from of a jQuery ID selector.

除了其他答案中列出的配置问题外,此错误还可能由您自己的代码中的一个简单错误触发:忘记了 jQuery ID 选择器中的“#”。

I had code looking like

我的代码看起来像

$('datenotset_2341').click(function(){
 ....etc....
});

(missing out the # in front of the "datenotset")

(错过了“datenotset”前面的#)

As well as (obviously) failing to work, it triggered this error message in Chrome.

除了(显然)无法工作外,它还在 Chrome 中触发了此错误消息。

回答by Kris Giesing

I ran into this issue in my own code. It turns out I was iterating over all properties on an event object as part of a debugging/inspection tool that I was using. In this particular instance I was using jQuery's $.extend to clone the object for later inspection, but I believe any of the standard iteration techniques in the various toolkits would have triggered the warning as well.

我在自己的代码中遇到了这个问题。事实证明,作为我正在使用的调试/检查工具的一部分,我正在迭代事件对象上的所有属性。在这个特定的例子中,我使用 jQuery 的 $.extend 来克隆对象以供以后检查,但我相信各种工具包中的任何标准迭代技术也会触发警告。

I mention it here because my initial thought of simply searching the code base for instances of layerX or layerY didn't help - the property was being referenced generically, not by name.

我在这里提到它是因为我最初的想法是简单地在代码库中搜索 layerX 或 layerY 的实例并没有帮助 - 属性被一般地引用,而不是按名称。