【问题标题】:SVG Filter: ScaleSVG 过滤器:缩放
【发布时间】:2018-11-21 22:41:39
【问题描述】:

我有一个 svg 图形,它使用 svg 过滤器附加了一个阴影。我需要缩放阴影,但找不到可以做到这一点的过滤器。有谁知道这是否可行?

<svg class="svg" width="155" height="460" viewbox="0 0 100 100" preserveAspectRatio ="xMidYMin meet">
    <filter id="shadow" class="shadow" width="200%" height="200%">
        <feOffset           dx="0" dy="30"              in="SourceAlpha"    result="offset" />
        <feFlood            flood-opacity="0.12"                            result="opacity" />
        <feComposite                                    operator="in"       in="opacity"        in2="offset"    result="opacityOffset"  />
        <feMerge class="everything">
            <feMergeNode in="opacityBlurOffset" />
            <feMergeNode in="SourceGraphic" />
        </feMerge>
    </filter>
    <circle class="circle"
            cx="50" 
            cy="50" 
            r="40"
            fill="tomato"
            filter="url(#shadow)"/>
</svg>

http://codepen.io/bradjohnwoods/pen/XXMPGY

【问题讨论】:

    标签: scale svg-filters


    【解决方案1】:

    您可以使用模糊放大阴影,然后使用不透明度映射(使用 feComponentTransfer/feFuncA)将模糊阴影边缘内的值调高至 0.12 - 泛光不透明度的值。像这样:

    <svg class="svg" width="155" height="460" viewbox="0 0 100 100" preserveAspectRatio ="xMidYMin meet">
    	<filter id="shadow" class="shadow" width="200%" height="200%">
    		<feOffset 			dx="0" dy="30" 				in="SourceAlpha"	result="offset" />
    		<feFlood 			flood-opacity="0.12"							result="opacity" />
    		<feComposite 									operator="in"       in="opacity"		in2="offset"	result="opacityOffset"	/>
    		<feGaussianBlur stdDeviation="5"/>
    		<feComponentTransfer result="opacityBlurOffset">
    			<feFuncA type="table" tableValues="0 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12 .12"/>
    		</feComponentTransfer>
    		
    		
    		<feMerge class="everything">
    			<feMergeNode in="opacityBlurOffset" />
    			<feMergeNode in="SourceGraphic" />
    		</feMerge>
    	</filter>
    	<circle class="circle"
    			cx="50" 
    			cy="50" 
    			r="40"
    			fill="tomato"
    			filter="url(#shadow)"/>
    </svg>

    我应该注意到您的原始代码有一个悬挂引用 - 用作您的 feMergeNode “in”的 opacityBlurOffset 没有引用以前的结果。

    【讨论】:

      【解决方案2】:

      对于那些正在寻找的人。像上面的解决方案,但没有嘈杂的边缘:

      <svg xmlns="http://www.w3.org/2000/svg" width="250" height="41.66666666666667" vector-effect="non-scaling-stroke" style="overflow: visible; width: 100%; height: 100%; pointer-events: none;">
          <defs>
              <linearGradient id="gradient-647049" gradientTransform="rotate(0)">
                  <stop offset="0%" stop-color="#320606" stop-opacity="100"></stop>
                  <stop offset="100%" stop-color="#FF0000" stop-opacity="100"></stop>
              </linearGradient>
              <filter id="shadow" color-interpolation-filters="sRGB" x="-100%" y="-100%" width="300%" height="300%">
                  <feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" in="SourceGraphic" result="shadow_color"></feColorMatrix>
                  <feGaussianBlur in="shadow_color" stdDeviation="5" result="a-shadow_blur"></feGaussianBlur>
              </filter>
          </defs>
          <use xlink:href="#shape"
              x="50" y="50" transform="scale(1.212)" filter="url(#shadow)"
              style="transform-origin: 50% 50% 0px;"></use>
          <ellipse id="shape" cx="125" cy="20.833333333333336" rx="120.5" ry="16.333333333333336" fill="url(#gradient-647049)"
              stroke="rgba(27,117,221,1)" stroke-width="9" stroke-linejoin="round"></ellipse>
      </svg>

      【讨论】:

        猜你喜欢
        • 2016-05-20
        • 1970-01-01
        • 2015-02-08
        • 1970-01-01
        • 2015-09-17
        • 1970-01-01
        • 2011-05-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多