如果可能,如何在CSS中反转图像(jpg / png ..)的颜色?
Answers:
filter: url(data:image/svg+xml;base64,PHN2Z...<long address>...PC9zdmc+#invert);
,可以吗?
filter: url("data:image/svg+xml;utf8,<svg height='0' xmlns='http://www.w3.org/2000/svg'><filter id='blur'><feGaussianBlur stdDeviation='5' /></filter></svg>");
但它不...任何想法?
您可以通过javascript应用样式。这是下面的Js代码,它将过滤器应用于ID为theImage的图像。
function invert(){
document.getElementById("theImage").style.filter="invert(100%)";
}
这是
<img id="theImage" class="img-responsive" src="http://i.imgur.com/1H91A5Y.png"></img>
现在您需要做的就是调用invert()单击图像时执行此操作。
function invert(){
document.getElementById("theImage").style.filter="invert(100%)";
}
<h4> Click image to invert </h4>
<img id="theImage" class="img-responsive" src="http://i.imgur.com/1H91A5Y.png" onClick="invert()" ></img>
我们在我们的网站上使用它
对于从0到1的反向转换,您可以使用此库InvertImages,该库提供对IE 10的支持。我也对IE 11进行了测试,它应该可以工作。