我认为,如果您要制作动画 svg,它将用于网络用途。不是吗?
如果是这种情况,我建议避免使用从 Illustrator 或 Coreldraw 导出的 svg,因为两者都会用稀有且不清晰的代码过度填充 svg 代码。我的建议是改用 Inkscape,因为它是原生 svg 编辑器。无论 Inkscape 是否还添加了一些与软件布局相关的代码,通过在文本编辑器中打开 svg 并删除所有额外代码或使用像 SVGO 这样的库(也有一个免费的网络应用程序来完成),可以很容易地清理它.请参阅此处的工具 SVGOMG
我将提供同一个 svg 的两个代码版本,以便您理解我在说什么。
这就是 Inkscape 保存 svg 的方式:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="448.12128"
height="2239.0315"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="animated.svg">
<metadata
id="metadata14">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs12" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1366"
inkscape:window-height="702"
id="namedview10"
showgrid="false"
fit-margin-top="10"
fit-margin-left="10"
fit-margin-right="10"
fit-margin-bottom="10"
inkscape:zoom="0.061636364"
inkscape:cx="-3732.3292"
inkscape:cy="2149.3007"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg2" />
<path
style="fill:#0029b4;fill-opacity:1"
inkscape:connector-curvature="0"
d="m 11.13017,1988.6745 212.92999,240.357 212.92981,-240.357 z m 0,-1978.6745 425.8598,0 1.13131,242.01964 -428.12128,0 z m 0,338.49925 425.8598,0 0,1543.67415 -425.8598,0 z"
id="path8" />
</svg>
这是优化后的svg:
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="448.12128" height="2239.0315">
<path style="fill:#0029b4;fill-opacity:1" d="m 11.13017,0 z"/>
</svg>
这是你的 html,我的 svg 正在运行:
#sobreU{fill: rgb(182,236,222);
stroke:#119094;
stroke-width:2px;
stroke-dashoffset:2150 ;
stroke-dasharray: 2150;
animation: line 2s ease-in-out forwards;
}
@keyframes line{
100%{
stroke-dashoffset: 0;
}
0%{
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=0.5">
<title>Document</title>
</head>
<body>
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="1044" height="364">
<path id="sobreU" d="M 923.0842,353.33646 1034,182.12299 923.0842,10.90966 Z M 10,353.33646 10,10.90966 121.68301,10 l 0,344.24521 z m 156.20465,-342.4268 712.34799,342.4268 z"/>
</svg>
</body>
</html>
另请注意,您代码中的 svg 缺少最后一个结束标记 </svg>
并在此处重新声明 path
的结束标记:186z"/> </path>
如果您使用 /
在 path
d
声明的末尾,则不能使用 </path>
,因为 /
关闭了标记。页面显示 svg 是因为它嵌入到 html 代码中,并且 html 不像 svg 那样严格,但是如果您尝试在浏览器中单独打开 svg,它会丢弃以下错误消息。
希望对我的英语有所帮助和抱歉。
本文链接:https://www.f2er.com/8057.html