2015-02-17 81 views
0

我有一个svg图像作为一个按钮。当您将鼠标悬停在按钮上时,svg填充将更改为其他颜色,但我也希望我创建的内部阴影滤镜也可以显示。也就是说,要从0%不透明度变为100%。是否可以使用CSS代码为SVG滤镜的不透明度设置动画效果?

我能够用css转换来改变填充颜色。是否有可能用css改变滤镜的不透明度?

下面是SVG代码:

<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" 
width="36.25px" height="23px" viewBox="5 -5 36.25 23" enable-background="new 0 0 36.25 23" xml:space="preserve"> 

<!--Definiciones del Filtro--> 
<filter id="sombra" x="-50%" y="-50%" width="200%" height="200%"> 
<feComponentTransfer in="SourceAlpha"> 
<feFuncA type="table" tableValues="1 0" /> 
</feComponentTransfer> 
<feGaussianBlur stdDeviation="1"/> 
<feOffset dx="-1" dy="-1" result="offsetblur"/> 
<feFlood flood-color="rgb(20, 0, 0)" result="color"/> 
<feComposite in2="offsetblur" operator="in"/> 
<feComposite in2="SourceAlpha" operator="in" /> 
<feMerge> 
<feMergeNode in="SourceGraphic" /> 
<feMergeNode /> 
</feMerge> 
</filter> 

<g filter="url(#sombra)"> 
<polygon points="23.671,8.625 23.671,4.657 21.786,4.657 21.786,7.513 18.255,5.433 18.194,5.398 18.058,5.398 
4.724,13.249 5.502,14.57 7.862,13.179 7.862,18.343 9.396,18.343 9.396,12.276 18.128,7.138 26.854,12.276 26.854,18.343 
28.388,18.343 28.388,13.179 30.75,14.57 31.526,13.249 "/> 

<rect x="15.289" y="11.553" width="2.44" height="2.444"/> 
<rect x="18.523" y="11.553" width="2.438" height="2.444"/> 
<rect x="15.289" y="14.656" width="2.44" height="2.439"/> 
<rect x="18.523" y="14.656" width="2.438" height="2.439"/> 
</g> 
</svg> 

这里是CSS:

#Capa_1{ 
fill:#FFFFFF; 
-webkit-transition: fill 0.3s; 
} 

#Capa_1:hover{ 
fill:#8A653B; 
} 

在此先感谢...!

+0

是这样的? [CODEPEN](http://codepen.io/shadowman86/pen/azYNYb) – innovation 2015-02-18 00:10:19

+0

不,不是。这个想法是从白色的形象开始,内在的影子是不可见的。然后,当您将鼠标悬停在按钮上时,颜色和过滤器都应该可见。谢谢! – 2015-02-18 01:37:47

回答

-1

MDN doc动画过滤的工作草案。

not a lot of support是目前市面上:(

而且对SVG元素只在Firefox

下面是火狐狸用户小提琴:Fiddle

应用的SVG滤镜:filter: url(#filterid)
应用svg不透明度滤镜:filter: opacity(50%);
并合并:filter: url(#filterid) opacity(50%);

+0

真的吗?仅适用于Firefox? :那是跛脚。小提琴看起来完全像我试过的,在Chrome和IE上都没有结果。没有任何解决方法吗?谢谢! – 2015-02-18 01:39:44

+0

哦,我还注意到,通过在过滤器中添加“不透明度”线,您不会修改过滤器的不透明度,但相反会自行添加和修改不透明度过滤器。 – 2015-02-18 02:01:19

+0

yh您可能必须在自定义过滤器中包含不透明度(如果可能的话): 但是即使svg上的过滤器也是相当实验性的,所以您在Web浏览器中做这种事情有点提前。 – Persijn 2015-02-18 09:04:57

相关问题