【发布时间】:2022-04-22 02:08:30
【问题描述】:
我是 SVG 和其他东西的新手,我正在尝试为单个笔划的不同短划线添加不同的颜色。
<style>
.c-dashed-line__path {
animation: c-dashed-line-path 5s forwards;
fill: none;
stroke: rgb(255, 32, 32);
stroke-dasharray: 1475;
stroke-dashoffset: 1475;
stroke-width: 60;
}
.c-dashed-line__dash {
fill: none;
stroke: #FFFFFF;
stroke-dasharray: 40 200 40 480;
stroke-dashoffset: 40;
stroke-width: 70;
}
@keyframes c-dashed-line-path {
from {
stroke-dashoffset: 1474;
}
to {
stroke-dashoffset: 0;
}
}
</style>
<svg id="svg11"
viewBox="0 0 2133.3333 1200"
height="1200"
width="2133.3333"
version="1.1">
<metadata
id="metadata16">
<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>
<g
id="layer2">
<path
id="c-dashed-line" class="path2"
d="m 548.50746,29.104478 c 0,0 136.56717,279.850742 228.35821,293.283582 91.79105,13.43284 91.79105,13.43284 91.79105,13.43284 0,0 154.47758,22.38806 214.92538,134.32835 60.4478,111.9403 40.2985,203.73135 147.7612,295.52239 107.4627,91.79105 208.2089,-6.71642 380.597,114.17911"
style="fill:none;" />
</g>
</defs>
<use class="c-dashed-line__path" xlink:href="#c-dashed-line"/>
<!-- A dashed white line that sits on top of the solid green line -->
<use class="c-dashed-line__dash" xlink:href="#c-dashed-line"/>
</svg>
请看看我到目前为止做了什么。 https://codepen.io/geekudu/pen/QWWvqRp
我打算为每个破折号使用不同的颜色。 任何帮助表示赞赏。提前致谢
【问题讨论】:
-
将每个破折号绘制为单独的曲线。如果你正确地构造渐变,有时可以使用渐变绘制不同的颜色,但有时也是不可能的。