【发布时间】:2020-04-12 23:19:00
【问题描述】:
我正在尝试发现缩放 svg 模式的方法,以便该模式不会被使用它的元素的边界切割。然而,这种模式正在重复以覆盖该元素。
假设我有一个 20px 半径的圆作为图案。 将其应用于 80px 宽度的元素:
现在元素被缩放到 90px,图案应该水平拉伸(不需要保持纵横比):
最后,放大到 90 像素以上会增加另一个圆圈的出现(本示例中为 95 像素宽度 - 纵横比仍然被忽略):
我可以添加一些脚本来实现该效果。但我很好奇我是否可以使用纯 SVG 获得这种行为。
<svg style='display: block; height: 60px; width: 95px; '>
<defs>
<pattern patternUnits='userSpaceOnUse' viewBox='0 0 20 20' width='20' height='20' id='the_pattern'>
<circle cx='10' cy='10' r='10' stroke-width='0' fill='black'></circle>
</pattern>
</defs>
<rect x='0' y='0' width='80' height='20' fill='url(#the_pattern)'></rect>
<rect x='0' y='20' width='90' height='20' fill='url(#the_pattern)'></rect>
<rect x='0' y='40' width='95' height='20' fill='url(#the_pattern)'></rect>
</svg>
【问题讨论】:
-
你能发布你使用的svg元素吗?
-
当然。为问题添加了一些基本代码。