Modify SVG fill color when being served as Background-Image

后端 未结 16 1011
再見小時候
再見小時候 2020-11-22 06:31

Placing the SVG output directly inline with the page code I am able to simply modify fill colors with CSS like so:

po         


        
16条回答
  •  隐瞒了意图╮
    2020-11-22 06:59

    Now you can achieve this on the client side like this:

    var green = '3CB54A';
    var red = 'ED1F24';
    var svg = ' ';      
    var encoded = window.btoa(svg);
    document.body.style.background = "url(data:image/svg+xml;base64,"+encoded+")";
    

    Fiddle here!

提交回复
热议问题