How is the getBBox() SVGRect calculated?

后端 未结 7 1637
再見小時候
再見小時候 2020-12-04 15:29

I have a g element that contains one or more path elements. As I mentioned in another question, I scale and translate the g element by

7条回答
  •  鱼传尺愫
    2020-12-04 16:02

    there are at least 2 easy but somewhat hacky ways to do what you ask... if there are nicer (less hacky) ways, i haven't found them yet

    EASY HACKy #1:
    a) set up a rect that matches the "untransformed" bbox that group.getBBox() is returning
    b) apply the group's "unapplied transform" to that rect
    c) rect.getBBox() should now return the bbox you're looking for

    EASY HACKY #2: (only tested in chrome)
    a) use element.getBoundingClientRect(), which returns enough info for you to construct the bbox you're looking for

提交回复
热议问题