我想feColorMatrix
在网页中使用SVG过滤器。以前,我成功地使其在Firefox和Chrome中都可以工作(具有css属性filter:url()
)。但是,这在IE中不起作用,这要求我同时插入图像和SVG过滤器。
我正在寻找图像上的过滤器,当图像悬停时该过滤器会淡出或消失。我以为使用同一张图片两次(一个带有过滤器,另一个不带过滤器),因此我可以使经过过滤的图像在悬停时消失,但仍保留未过滤的图像。
问题在于过滤器不再显示。两个图像均未过滤。我的问题是:到目前为止,我的代码有什么问题?我想达到的效果是否有更好的解决方案?
在此先感谢您的建议/指示!
这是我到目前为止的代码:
CSS:
svg {
width:30%;
float:left;
overflow:hidden;
height:300px;
}
svg image {
position:absolute;
left:0px;
}
svg .img1 {
z-index:2;
}
svg .img2 {
z-index:1;
}
svg:hover .img1 {
opacity:0;
}
的HTML:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMax slice" viewBox="0 0 662 1000">
<defs>
<filter id="sepiatone">
<feColorMatrix values="0.3 0.4 0.2 0 0, 0.15 0.25 0.1 0 0, 0.05 0.2 0.1 0 0, 0 0 0 1 0" />
</filter>
</defs>
<image xlink:href="/CMS/uploads/img/upload_2.jpg" class='img1' filter="url(#sepiatone)" width='662px' height='1000px' />
<image xlink:href="/CMS/uploads/img/upload_2.jpg" class='img2' width='662px' height='1000px' />
</svg>
更新
我想我要去那里!image
我没有在SVG中放置两个标签,而是使用该use
标签对它进行了两个引用。另外,迈克尔指出z-index不起作用。因此,我将过滤后的图像放置在DOM中的最新位置。将鼠标悬停在SVG上后,过滤后的SVG的不透明度会发生变化,从而显示出未过滤的图像。谢谢迈克尔的指点!我会接受您的回答,因为它指出了这个问题。
这是代码:
HTML:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMax slice" viewBox="0 0 662 1000">
<defs>
<filter id="sepiatone">
<feColorMatrix values="0.3 0.4 0.2 0 0, 0.15 0.25 0.1 0 0, 0.05 0.2 0.1 0 0, 0 0 0 1 0"></feColorMatrix>
</filter>
<g id="imgR">
<image xlink:href="/CMS/uploads/img/upload_2.jpg" width='662px' height='1000px'></image>
</g>
</defs>
<use xlink:href="#imgR" class='img2'></use>
<use xlink:href="#imgR" class='img1' filter="url(#sepiatone)"></use>
</svg>
CSS:
svg {
width:30%;
float:left;
overflow:hidden;
height:300px;
}
svg .img1, svg .img2 {
position:absolute;
left:0px;
width:100%;
}
svg:hover .img1 {
opacity:0;
}
不幸的是,SVG不支持z-indexing。您最想要的内容必须在DOM中列在最后。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句