← 返回首页
SVGPathElement: pathLength property - Web APIs | MDN

SVGPathElement: pathLength property

The pathLength read-only property of the SVGPathElement interface reflects the pathLength attribute of the given <path> element.

In this article

Value

An SVGAnimatedNumber.

Examples

Accessing the pathLength Property

html
<svg width="200" height="100"> <path id="myPath" d="M 0,30 h100" pathLength="50" /> </svg>
js
const pathElement = document.getElementById("myPath"); // Access the pathLength property const animatedNumber = pathElement.pathLength; // The base value of the pathLength attribute console.log(animatedNumber.baseVal); // Output: 100

Specifications

Specification
SVG Paths
# __svg__SVGPathElement__pathLength

Browser compatibility

Enable JavaScript to view this browser compatibility table.

See also