spreadMethod - SVG: Scalable Vector Graphics 编辑

The spreadMethod attribute determines how a shape is filled beyond the defined edges of a gradient.

Two elements are using this attribute: <linearGradient> and <radialGradient>

Context notes

Valuepad | reflect | repeat
Initial valuepad
AnimatableYes
pad
This value indicates that the final color of the gradient fills the shape beyond the gradient's edges.
reflect
This value indicates that the gradient repeats in reverse beyond its edges.
repeat
This value specifies that the gradient repeats in the original order beyond its edges.

Defining a gradient's edges

By default, a gradient reaches to the edges of the shape being filled. To see the effects of this attribute, you will need to set the size of the gradient smaller than the shape.

In the case of a linear gradient, the edges may be defined as a rectangle by the x1, x2, y1 and y2 attributes. In the case of a radial gradient, the edges may be defined as outer and inner circles by the cx, cy and r (outer) and fx, fy and fr (inner) attributes.

Examples of spreadMethod with linear gradients

SVG

<svg width="220" height="150" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <linearGradient id="PadGradient"
                    x1="33%" x2="67%">
      <stop offset="0%"  stop-color="fuchsia"/>
      <stop offset="100%" stop-color="orange"/>
    </linearGradient>
    <linearGradient id="ReflectGradient" spreadMethod="reflect"
                    x1="33%" x2="67%">
      <stop offset="0%"  stop-color="fuchsia"/>
      <stop offset="100%" stop-color="orange"/>
    </linearGradient>
    <linearGradient id="RepeatGradient" spreadMethod="repeat"
                    x1="33%" x2="67%">
      <stop offset="0%"  stop-color="fuchsia"/>
      <stop offset="100%" stop-color="orange"/>
    </linearGradient>
  </defs>

  <rect fill="url(#PadGradient)"
          x="10" y="0" width="200" height="40"/>
  <rect fill="url(#ReflectGradient)"
          x="10" y="50" width="200" height="40"/>
  <rect fill="url(#RepeatGradient)"
          x="10" y="100" width="200" height="40"/>
</svg>

Result

Notice that the middle third of each gradient is the same. The outer thirds show the difference between the three spread methods.

Examples of spreadMethod with radial gradients

SVG

<svg width="340" height="120" xmlns="http://www.w3.org/2000/svg">
  <defs>
   <radialGradient id="RadialPadGradient"
                    cx="75%" cy="25%" r="33%"
                    fx="64%" fy="18%" fr="17%">
      <stop offset="0%"  stop-color="fuchsia"/>
      <stop offset="100%" stop-color="orange"/>
    </radialGradient>
    <radialGradient id="RadialReflectGradient"
                    spreadMethod="reflect"
                    cx="75%" cy="25%" r="33%"
                    fx="64%" fy="18%" fr="17%">
      <stop offset="0%"  stop-color="fuchsia"/>
      <stop offset="100%" stop-color="orange"/>
    </radialGradient>
    <radialGradient id="RadialRepeatGradient"
                    spreadMethod="repeat"
                    cx="75%" cy="25%" r="33%"
                    fx="64%" fy="18%" fr="17%">
      <stop offset="0%"  stop-color="fuchsia"/>
      <stop offset="100%" stop-color="orange"/>
    </radialGradient>
  </defs>

  <rect fill="url(#RadialPadGradient)"
        x="10" y="10" width="100" height="100"/>
  <rect fill="url(#RadialReflectGradient)"
        x="120" y="10" width="100" height="100"/>
  <rect fill="url(#RadialRepeatGradient)"
        x="230" y="10" width="100" height="100"/>
</svg>

Result

Specifications

SpecificationStatusComment
Scalable Vector Graphics (SVG) 2
The definition of 'spreadMethod for <radialGradient>' in that specification.
Candidate RecommendationNo change
Scalable Vector Graphics (SVG) 2
The definition of 'spreadMethod for <linearGradient>' in that specification.
Candidate RecommendationNo change
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'spreadMethod for <radialGradient>' in that specification.
RecommendationInitial definition for <radialGradient>
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'spreadMethod for <linearGradient>' in that specification.
RecommendationInitial definition for <linearGradient>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:67 次

字数:8736

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文