SVGLinearGradientElement: x2-Eigenschaft
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
Please help us by answering a few questions.
Die x2
schreibgeschützte Eigenschaft des SVGLinearGradientElement
-Interfaces beschreibt die x-Achsen-Koordinate des Startpunkts des Farbverlaufs als SVGAnimatedLength
. Sie spiegelt den berechneten Wert des x2
-Attributs auf dem <linearGradient>
-Element wider.
Der Attributwert ist eine <length>
, <percentage>
oder <number>
. Der numerische Wert des SVGAnimatedLength.baseVal
ist die x-Koordinate des Endpunkts des Farbverlaufs im Benutzerskoordinatensystem.
Wert
Ein SVGAnimatedLength
.
Beispiel
Für das folgende SVG:
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gradient1" x1="50%" y1="0%" x2="50%" y2="100%">
<stop offset="0%" stop-color="blue" />
<stop offset="100%" stop-color="white" />
</linearGradient>
<linearGradient id="gradient2" x1="25%" y1="0%" x2="75%" y2="100%">
<stop offset="0%" stop-color="red" />
<stop offset="100%" stop-color="yellow" />
</linearGradient>
</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>
Können wir auf die berechneten Werte der x2
-Attribute zugreifen:
const linearGradients = document.querySelectorAll("linearGradient");
const x2Gradient1 = linearGradients[0].x2;
const x2Gradient2 = linearGradients[1].x2;
console.dir(x2Gradient1.baseVal.value); // output: 100 (50% of 200)
console.dir(x2Gradient2.baseVal.value); // output: 150 (75% of 200)
Spezifikationen
Specification |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGLinearGradientElement__x2 |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
x2 |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support