【问题标题】:Why do the SVG properties of an SVG element sometimes show up as accessible and sometimes not?为什么 SVG 元素的 SVG 属性有时显示为可访问,有时却不能访问?
【发布时间】:2012-05-05 18:29:15
【问题描述】:
self.popover = self.canvas.append("svg:rect")
  .attr("id", popoverId)
  ...

self.popover.getBBox()
TypeError: Object [object SVGRectElement] has no method 'getBBox'

但是,如果我在单击时将另一个 SVG 元素作为“this”传递给函数,我就可以访问所有 SVG 方法。

【问题讨论】:

    标签: javascript svg d3.js


    【解决方案1】:

    这个 d3 方法可以解决问题:

    self.popover.node().getBBox()
    

    【讨论】:

    • 正确。 self.popover 是 D3 选择,而 self.popover.node() 是 SVGRectElement。
    猜你喜欢
    • 2011-08-27
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多