如何在SVG中定义或引用变量? [英] How do I define or reference a variable in SVG?

查看:2288
本文介绍了如何在SVG中定义或引用变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能你不需要静态图像的变量,但是当一切都以变量IMO定义时,这将更容易检查它们并查看相关的部分。它还简化了图像的更新。 查看您在SolidWorks中如何使用基于约束的工程图。它基本上使一个对象的大小相对于另一个对象的大小(或另一个属性)。我可以通过引用参考对象的宽度来类似地定义一个整数(宽度)或设置另一个对象的宽度。

Might be you do not need variables for static images but this would be easier to inspect them and see related parts when everything is defined in terms of variables, IMO. It also simplifies update of the images. See how you do the constrains-based engineering drawing in SolidWorks. It basically makes the sizes of one object relative to the size (or another property) of the other. Can I similarly define an integer (width) or set a width of another object by referencing the width of a reference object?

推荐答案

SVG参数变量规范会执行您想要的操作,但不太可能完成,更不用说由UA实施。相反SVG看起来像它将移向属性的CSS参数在哪一点你可以使用CSS Calc。

The SVG Parameter Variables Specification would do what you want but it's unlikely ever to be completed, let alone implemented by UAs. Instead SVG looks like it will move towards attributes being CSS parameters at which point you could use CSS Calc.

在隧道尽头有一个灯,这个规范已经实现了一个javascript垫片,所以如果你使用,你有一个已准备好的库,做你想要的下降。

There is a light at the end of the tunnel for you though as this specification is already implemented by a javascript shim so if you use that you have a ready made drop in library that does what you want.

语法看起来像这样...

The syntax looks like this...

<object type="image/svg+xml" data="map.svg">
  <param name="x" value="125" />
  <param name="y" value="108" />
</object>

<object type="image/svg+xml" data="map.svg?y=103&x=523">
</object>

用法如下...

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 320">
<script type="text/ecmascript" xlink:href="ref2.js" />

<ref id="paramX" param="x" default="-10"/>
<ref id="paramY" param="y" default="-10"/>

<circle id="coord" cx="url(#paramX)" cy="url(#paramY)" r="5" fill="tan" stroke="brown" stroke-width="3" />

a href =http://dev.w3.org/SVG/modules/ref/master/ref2.js>从这里

The library can be obtained from here

这篇关于如何在SVG中定义或引用变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆