Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. SVGRadialGradientElement
  4. cx

SVGRadialGradientElement: cx property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

Thecx read-only property of theSVGRadialGradientElement interface describes the x-axis coordinate of the center of the radial gradient as anSVGAnimatedLength. It reflects the computed value of thecx attribute on the<radialGradient> element.

The attribute value is a<length>,<percentage>, or<number>. The numeric value of theSVGAnimatedLength.baseVal is the x-coordinate of the radial gradient's center in the user coordinate system.

Value

AnSVGAnimatedLength.

Example

Given the following SVG:

html
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">  <defs>    <radialGradient cx="50" cy="75" r="30">      <stop offset="0%" stop-color="blue" />      <stop offset="100%" stop-color="white" />    </radialGradient>    <radialGradient cx="25%" cy="50%" r="10%">      <stop offset="0%" stop-color="red" />      <stop offset="100%" stop-color="yellow" />    </radialGradient>  </defs>  <rect x="0" y="0" width="200" height="100" fill="url(#gradient1)" />  <rect x="0" y="100" width="200" height="100" fill="url(#gradient2)" /></svg>

We can access the computed values of thecx attributes:

js
const radialGradients = document.querySelectorAll("radialGradient");const cxGradient1 = radialGradients[0].cx;const cxGradient2 = radialGradients[1].cx;console.dir(cxGradient1.baseVal.value); // output: 50console.dir(cxGradient2.baseVal.value); // output: 50 (25% of 200)

Specifications

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGRadialGradientElement__cx

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp