首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SVG动画图案边缘

SVG动画图案边缘
EN

Stack Overflow用户
提问于 2017-03-04 19:18:54
回答 1查看 340关注 0票数 3

我想创建条纹动画背景,但由于某些原因无法删除出现在图案边缘的垂直线。

下面是我的svg:

代码语言:javascript
运行
复制
<svg width="500" height="500">
      <defs>
		<linearGradient id='stripe-gradient' x1='0%' y1='0%' x2='100%' y2='100%'>
             <stop offset='0%'  stop-color='#AAA'></stop>
			 <stop offset='24.9%'  stop-color='#AAA'></stop>
             <stop offset='25%' stop-color='#666'></stop>
			 <stop offset='49.9%' stop-color='#666'></stop>
			 <stop offset='50%' stop-color='#AAA'></stop>
			 <stop offset='74.9%' stop-color='#AAA'></stop>
			 <stop offset='75%' stop-color='#666'></stop>
			 <stop offset='99.9%' stop-color='#666'></stop>
			 <stop offset='100%' stop-color='#AAA'></stop>
		</linearGradient>
        <pattern id='stripe-pattern' width='20' height='20' patternUnits='userSpaceOnUse' >
			  <rect x='-20' y='0' width='20' height='20' fill='url(#stripe-gradient)' stroke-width='0' stroke='none'>
			  	<animate attributeName='x' from='-20' to='0' dur='0.5s' repeatCount='indefinite'></animate>
			  </rect>
	          <rect x='0' y='0' width='20' height='20' fill='url(#stripe-gradient)' stroke-width='0' stroke='none'>
				  <animate attributeName='x' from='0' to='20' dur='0.5s' repeatCount='indefinite'></animate>
			  </rect>
        </pattern>
        <mask id='stripe-mask'>
          <rect x='0' y='0' width='100%' height='100%' fill='url(#stripe-pattern)' ></rect>
        </mask>      
      </defs>
      <rect class="hbar thing" x="0" y="0" width="200" fill="green" height="200" mask="url(#stripe-mask)"></rect>
    </svg>

EN

回答 1

Stack Overflow用户

发布于 2017-08-24 03:21:57

我知道这篇文章有点老了,但如果你仍然需要解决这个问题,我已经让它工作了两倍的条纹,删除了模式中的一个矩形,然后将最后一个矩形的大小加倍,c.f。,以下代码:

代码语言:javascript
运行
复制
<svg width="500" height="500">
    <defs>
        <linearGradient id='stripe-gradient' x1='0%' y1='0%' x2='100%' y2='100%'>
            <stop offset='0%'  stop-color='#AAA'></stop>
            <stop offset='12.45%'  stop-color='#AAA'></stop>
            <stop offset='12.5%' stop-color='#666'></stop>
            <stop offset='24.45%' stop-color='#666'></stop>
            <stop offset='25.5%'  stop-color='#AAA'></stop>
            <stop offset='37.45%'  stop-color='#AAA'></stop>
            <stop offset='37.5%' stop-color='#666'></stop>
            <stop offset='49.9%' stop-color='#666'></stop>
            <stop offset='50%' stop-color='#AAA'></stop>
            <stop offset='62.45%' stop-color='#AAA'></stop>
            <stop offset='62.5%' stop-color='#666'></stop>
            <stop offset='74.95%' stop-color='#666'></stop>
            <stop offset='75%' stop-color='#AAA'></stop>
            <stop offset='87.45%' stop-color='#AAA'></stop>
            <stop offset='87.5%' stop-color='#666'></stop>
            <stop offset='100%' stop-color='#666'></stop>
        </linearGradient>
        <pattern id='stripe-pattern' width='20' height='20' patternUnits='userSpaceOnUse' >
            <rect x='-20' y='0' width='40' height='40' fill='url(#stripe-gradient)' stroke-width='0' stroke='none'>
                <animate attributeName='x' from='-20' to='0' dur='0.5s' repeatCount='indefinite'></animate>
            </rect>
        </pattern>
        <mask id='stripe-mask'>
            <rect x='0' y='0' width='100%' height='100%' fill='url(#stripe-pattern)'></rect>
        </mask>      
    </defs>
    <rect x="0" y="0" width="200" fill="green" height="200" mask="url(#stripe-mask)"></rect>
</svg>

我认为当浏览器计算两个矩形的位置时,出现垂直条纹是由于一些小的数字问题造成的。因此,解决方案是只使用一个rect。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42595355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档