Drew Dara-Abrams
Drew Dara-Abrams

Reputation: 8054

determining length, slope, and other measurements of an SVG line segment

I'd like to use JavaScript to determine the length, slope, and other measurements of an existing SVG line segment (in screen pixels). I've been trying to use the jquery-svg plugin, but haven't had any luck. Any suggestions?

Upvotes: 3

Views: 1384

Answers (1)

Drew Dara-Abrams
Drew Dara-Abrams

Reputation: 8054

With more searching, I found some JavaScript methods that should do the job:

getTotalLength()

document.getElementById("segment-line-c2200").getTotalLength()

returns 205.11094665527344

getBBox()

document.getElementById("segment-line-c2200").getBBox()

returns

SVGRect
  height: 32.8560791015625
  width: 202.4622802734375
  x: 1617.7255859375
  y: 2013.96435546875
  __proto__: SVGRect

Upvotes: 2

Related Questions