rveciana / svg-path-properties

Pure Javascript alternative to path.getPointAtLength(t) and getTotalLength() functions. Works with Canvas & Node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I cannot use getTotalLength method.

hiroyaiizuka opened this issue · comments

Browser: Google Chrome
Editor: VScode

I'm now creating SVG animation with scrolling effect.
But I'm facing a trouble.

When I code like below, there is an error.

`

<script>
  (function() {
    "use strict";

    window.onload = function() {
      const line = document.querySelector("line");

      const pathLength = line.getTotalLength();
      console.log(pathLength);
    };
  })();
</script>
`

Uncaught TypeError: Cannot read property property 'getTotalLength' of null.
Could you tell me the reason why this happens?

beacause a line is not a path. I think https://svgjs.com can do this

@meodai answer's correct. I close the issue

beacause a line is not a path. I think https://svgjs.com can do this

Can you suggest some solution?

To which problem?
The original problem was that the object was null. The solution is passing a valid object.

To which problem?
The original problem was that the object was null. The solution is passing a valid object.

I am having a multi line chart and I want to get length of each line using path.node().getTotalLength(). But it is not giving me the length.

But do you get the d property? That's where you have the path. You could console.log the value for path.node().getTotalLength() and check if it's an svg path.