【问题标题】:What are the practical implications of properties and methods being moved to other interfaces in web API?将属性和方法移至 Web API 中的其他接口有什么实际意义?
【发布时间】:2020-05-24 15:00:45
【问题描述】:

https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement 中,注释是这样写的:

注意:在 SVG 2 中,getPathSegAtLength() 和 createSVGPathSeg* 方法被移除,pathLength 属性和 getTotalLength() 和 getPointAtLength() 方法被移到 SVGGeometryElement .

这有什么实际意义?到目前为止,我正在做的事情,例如:

document.getElementById("myPath") --> myPath.isPointInStroke()

并且工作正常。

【问题讨论】:

    标签: javascript svg webapi pathelement


    【解决方案1】:

    path、rect、circle、ellipse、polygon、polyline 和 line 元素都派生自 SVG 2 中的SVGGraphicsElement。将方法从 SVGPathElement 移动到 SVGGraphicsElement 使它们可用于所有子类。

    因此,在 SVG 2 中,您可以在圆上调用 getTotalLength(),这将导致浏览器返回 2πr,而在 SVG 1.1 中,您只能获取路径元素的总长度。

    【讨论】:

    • 那么我是否理解该更改并没有真正改变您使用它的方式(在路径元素上调用它),但基本上它在链中“向上移动”所以它的方法适用于更多样化的元素?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 2021-11-28
    • 1970-01-01
    • 2020-01-30
    • 2011-03-23
    相关资源
    最近更新 更多