简体   繁体   中英

Change svg fill color via colorpicker

I have the following question. is it possible to change the fill color of the svg file with the colorpicker. So far I have come to a moment where I can change the color of the background, but it would be best to change the color of the graphics as if it were a background or foreground. I would be very grateful for the help because I am a person who is just learning to program in jquery and does not understand everything yet. Underneath I attach my code. Pictures placed in the diva are changed using the buttons so they change dynamically. Once again, I will be very grateful for your help.

<style>
.inner1
{
width: 500px;
height: 500px;
margin:0 auto;
position: absolute;
margin-bottom:0;  
border:solid 2px black;
overflown:none;
}
</style>
<html>
<div id="Image-Holder-fg" class="inner1 "  >  
<img  class="popart1" src ="img/DCIM/Animal/animal5.svg" style="width: 
1425px; height: 1425px;" />
<img  class="popart2" src ="img/DCIM/Animal/animal6.svg" style="width: 
1425px; height: 1425px;" />
<img  class="popart3" src ="img/DCIM/Animal/animal7.svg" style="width: 
1425px; height: 1425px;" />  
<img  class="popart4" src ="img/DCIM/Animal/animal8.svg" style="width: 
1425px; height: 1425px;" />
</div>
<div id="picker-fg"></div>
</html>

<script>
$('#picker-fg').colpick({
    flat:true,
    layout:'hex',
    submit:0,
    colorScheme:'dark',
    onChange:function(hsb,hex,rgb,el,bySetColor) {
    $("#Image-Holder-fg").css('background-color','#'+hex);

    if(!bySetColor) $(el).val(hex);
}
}).keyup(function(){
$(this).colpickSetColor(this.value);
});
</script>

使用SVG内联,这样您可以选择特定的节点并使用JS设置填充。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM