gpt4 book ai didi

html - 嵌入带有参数的 svg 对象

转载 作者:技术小花猫 更新时间:2023-10-29 12:40:47 25 4
gpt4 key购买 nike

谁有想法或提示

我想在 svg 标签中嵌入一个 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>

最佳答案

目前浏览器不支持以这种方式传递参数,尽管有一个 SVG Parameters spec由 W3C 开发。规范中的示例使用 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>

关于html - 嵌入带有参数的 svg 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7397962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com