就业培训     下载中心     Wiki     联络
登录   注册

Log
  1. 首页
  2. SVG:可伸缩向量图形
  3. SVG Attribute reference
  4. spreadMethod

内容表

  • Context notes
  • Examples of spreadMethod with linear gradients
  • Examples of spreadMethod with radial gradients
  • 规范
  • 浏览器兼容性

spreadMethod

  1. SVG 元素
    1. A
      1. <a>
      2. <altGlyph>
      3. <altGlyphDef>
      4. <altGlyphItem>
      5. <animate>
      6. <animateColor>
      7. <animateMotion>
      8. <animateTransform>
    2. B-C
      1. <circle>
      2. <clipPath>
      3. <color-profile>
      4. <cursor>
    3. D
      1. <defs>
      2. <desc>
    4. E
      1. <ellipse>
    5. F
      1. <feBlend>
      2. <feColorMatrix>
      3. <feComponentTransfer>
      4. <feComposite>
      5. <feConvolveMatrix>
      6. <feDiffuseLighting>
      7. <feDisplacementMap>
      8. <feDistantLight>
      9. <feFlood>
      10. <feFuncA>
      11. <feFuncB>
      12. <feFuncG>
      13. <feFuncR>
      14. <feGaussianBlur>
      15. <feImage>
      16. <feMerge>
      17. <feMergeNode>
      18. <feMorphology>
      19. <feOffset>
      20. <fePointLight>
      21. <feSpecularLighting>
      22. <feSpotLight>
      23. <feTile>
      24. <feTurbulence>
      25. <filter>
      26. <font>
      27. <font-face>
      28. <font-face-format>
      29. <font-face-name>
      30. <font-face-src>
      31. <font-face-uri>
      32. <foreignObject>
    6. G
      1. <g>
      2. <glyph>
      3. <glyphRef>
    7. H
      1. <hkern>
    8. I
      1. <image>
    9. J-L
      1. <line>
      2. <linearGradient>
    10. M
      1. <marker>
      2. <mask>
      3. <metadata>
      4. <missing-glyph>
      5. <mpath>
    11. N-P
      1. <path>
      2. <pattern>
      3. <polygon>
      4. <polyline>
    12. Q-R
      1. <radialGradient>
      2. <rect>
    13. S
      1. <script>
      2. <set>
      3. <stop>
      4. <style>
      5. <svg>
      6. <switch>
      7. <symbol>
    14. T
      1. <text>
      2. <textPath>
      3. <title>
      4. <tref>
      5. <tspan>
    15. U
      1. <use>
    16. V-Z
      1. <view>
      2. <vkern>

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

You can use this attribute with the following SVG elements:

  • <linearGradient>
  • <radialGradient>

Context notes

值 pad | reflect | repeat
初始值 pad
Animatable Yes
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


>



										

结果

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>

										

结果

规范

规范 状态 注释
Scalable Vector Graphics (SVG) 2
The definition of 'spreadMethod for <radialGradient>' in that specification.
候选推荐 无变化
Scalable Vector Graphics (SVG) 2
The definition of 'spreadMethod for <linearGradient>' in that specification.
候选推荐 无变化
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'spreadMethod for <radialGradient>' in that specification.
推荐 Initial definition for <radialGradient>
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of 'spreadMethod for <linearGradient>' in that specification.
推荐 Initial definition for <linearGradient>

浏览器兼容性

No compatibility data found for svg.attributes.presentation.spreadMethod .
Check for problems with this page or contribute missing data to mdn/browser-compat-data .

Found a problem with this page?

  • Edit on GitHub
  • Source on GitHub
  • Report a problem with this content on GitHub
  • Want to fix the problem yourself? See our Contribution guide .

最后修改: Sep 23, 2021 , 由 MDN 贡献者

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1