jquery - 您应该如何在 Chrome 浏览器上利用即将弃用的方法来处理 jQuery?

标签 jquery google-chrome svg npm deprecation-warning

我有一些 NPM,它们具有使用 jQuery 对 SVG 元素进行选择的依赖项。下面是当我的 NPM 使用 jQuery 进行 SVG 选择时收到的警告。

<小时/>

'SVGElement.offsetWidth' is deprecated and will be removed in M50, around April 2016. See https://www.chromestatus.com/features/5724912467574784 for more details. locuslabs.js:6635 'SVGElement.offsetHeight' is deprecated and will be removed in M50, around April 2016. See https://www.chromestatus.com/features/5724912467574784 for more details.

Chrome 建议如下:

"These attributes should only be supported on HTMLElement, but have been supported on all Elements in WebKit and Blink. getBoundingClientRect() can typically be used as a replacement." -philipj@opera.com

这是创建此特定警告的 jQuery 代码部分。

function getWidthOrHeight( elem, name, extra ) {
// Start with offset property, which is equivalent to the border-box value
var valueIsBorderBox = true,
    val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
    styles = getStyles( elem ),
    isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
...
<小时/>

问题:

NPM 是否提供了一种方法来修改 NPM 使用哪个版本的 jQuery 作为依赖项?这是解决这个问题的最佳方法,还是我应该以不同的方式解决这个问题?澄清一下,这不是一个技术问题,而是一个最佳实现问题。

最佳答案

当涉及到开源的东西时,检查他们的问题线程以解决您的问题通常是一个好主意。如果您发现问题没有被描述,请创建一个新问题。然后,您可以专注于更新开源库,而不是使用已弃用的方法强制为库提供某种填充解决方案。

<小时/>

此问题正在 jQuery 的 Github 问题主题上进行审查和跟踪:

https://github.com/jquery/jquery/issues/2895

<小时/>

更新审核结果:

It seems no one really needs an offsetParent equivalent in non-legacy APIs so I'll close this issue. We don't support SVG nodes with a few exceptions and since offsetParent was never implemented in every popular browser, no web-facing code should depend on it.

a crash, or even an exception, won't happen when these attributes are removed. What will happen is that if you're using jQuery older than 2.2.0, the :visible selector will match no SVG element and :hidden will match all SVG elements, i.e. SVG elements are always considered hidden.

With jQuery 2.2.0 (79bcb29) this has been fixed and you shouldn't need to do anything at all.

关于jquery - 您应该如何在 Chrome 浏览器上利用即将弃用的方法来处理 jQuery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35279625/

相关文章:

javascript - 使用 jquery 预览文本

javascript - 为什么这个普通的 JavaScript 可以工作,而它等效的 jQuery 会失败?

javascript - 在 jquery.ajax 中重新使用变量

html - 如何让系统在非全屏 html5 视频上休眠?

javascript - 加载和显示 svg

jquery - 从 MVC4 中的 @Html.ValidationSummary() 中删除项目符号

javascript - Chrome 随机滚动 Javascript 事件

html - HTML 中的样式下拉元素

javascript - 如何从 rest-api 在 Angular 中的图像上显示加载指示器

javascript - 如何使用普通 JavaScript 更改此 SVG Sprite 的 href?