Invert colors of an image in CSS or JavaScript

后端 未结 4 504
慢半拍i
慢半拍i 2020-12-12 15:53

How do I invert colors of an image (jpg/png..) in either css if possible or javascript?

Previous related questions don\'t give enough detail.

4条回答
  •  佛祖请我去吃肉
    2020-12-12 15:59

    You can apply the style via javascript. This is the Js code below that applies the filter to the image with the ID theImage.

    function invert(){
    document.getElementById("theImage").style.filter="invert(100%)";
    }
    

    And this is the

    
    

    Now all you need to do is call invert() We do this when the image is clicked.

    function invert(){
    document.getElementById("theImage").style.filter="invert(100%)";
    }

    Click image to invert

    We use this on our website

提交回复
热议问题