【问题标题】:Embed a svg object with parameter嵌入带参数的 svg 对象
【发布时间】:2011-11-15 21:53:34
【问题描述】:

谁有想法或提示

我想在 die svg Tag 中嵌入一个 svg 对象并更改此参数

HTML/SVG(不继续)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>Test</title>   
</head>
<body>
<svg width="2000" height="2000">
       <object type="image/svg+xml" data="lamp.svg" style="width: 450px; height:150px;">
          <param name="color" value="yellow" />
       </object>
</svg>
</body>
</html>

SVG 文件 lamp.svg:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="40" height="40">
<title>lamp</title>
  <circle cx="30" cy="30" r="15" fill="param(color)" stroke-width=""/>
</svg>

使用 IMAGE TAG 不能传递任何标签参数。

<image x="0" y="0" width="20" height="20" xlink:href="lamp.svg"><param name="color" value="yellow" /></image>

【问题讨论】:

    标签: html object svg


    【解决方案1】:

    目前浏览器不支持以这种方式传递参数,尽管 W3C 正在开发一个SVG Parameters spec。规范中的示例使用a script 来模拟对该功能的支持。

    注意:垫片 param.js goes in the SVG file,而不是 html 文件:

    例如,

    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink"
    width="68" height="68">
    <rect x="10" y="10" height="48" width="48" stroke="black" stroke-width="1" fill="param(color) red">
    </rect>
    <rect x="29" y="0" height="10" width="10" fill="black"></rect>
    <text x="24" y="46" fill="param(text) black" style="font-size:32px;"
      content-value="param(number) 1">1</text>
    
    <script type="text/ecmascript" xlink:href="param.js" /> 
    
    </svg>
    

    【讨论】:

    • 自 2011 年以来对此有何更改?
    • 据我所知,浏览器方面没有任何改变。
    • 如何在嵌入 svg 的文档中指定参数值?该脚本仅在 svg 文件中查找参数...
    • 可能作为 url 参数跟在 svg 文档路径之后。
    猜你喜欢
    • 2020-04-07
    • 1970-01-01
    • 2020-07-02
    • 2023-04-03
    • 2011-02-09
    • 2017-08-13
    • 1970-01-01
    • 2015-08-13
    • 2017-11-18
    相关资源
    最近更新 更多