Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables SVG:生成一个元素';s属性依赖于另一个元素的属性_Variables_Svg_Properties_Reference - Fatal编程技术网

Variables SVG:生成一个元素';s属性依赖于另一个元素的属性

Variables SVG:生成一个元素';s属性依赖于另一个元素的属性,variables,svg,properties,reference,Variables,Svg,Properties,Reference,我有一个简单的SVG树,其中我希望rect2的x属性依赖于(引用)rect1的宽度: <rect id="rect1" style="fill:black" x="35" y="0" width="30" height="40" /> <rect id="rect2" style="fill:black" x="**rect1.width**" y="40" width="26" height="10" /> 这在SVG中是可能的,我在yahoogle或SVG引用中

我有一个简单的SVG树,其中我希望rect2的x属性依赖于(引用)rect1的宽度:

<rect id="rect1" style="fill:black" x="35" y="0" width="30" height="40" />
<rect id="rect2" style="fill:black" x="**rect1.width**" y="40" width="26" height="10" />

这在SVG中是可能的,我在yahoogle或SVG引用中找不到它

另一种方法是变量

**var widthOfRect1 = 30**
<rect id="rect1" style="fill:black" x="35" y="0" width="widthOfRect1" height="40" />
<rect id="rect2" style="fill:black" x="widthOfRect1" y="40" width="26" height="10" />
**var-widthofret1=30**
有办法吗?我知道你可以传递参数,但这不是我想要的


想法?

对于突变事件,可以选择这样做

创造小提琴


随着rect1宽度的增加,rect2的x在
domatrtrmedited
处理程序中发生更改。

对,这就行了。谢谢,不过这会让我有很多额外的剧本。我希望有一个更原生的SVG解决方案来解决这个问题。也许没有?你可以检查一下你是否做了你想要的。