lundi 30 décembre 2019

How could I make a dynamic banner change background color with JS based on a image?

I'm making some dynamic banners and I wanted to reduce the number of variants with eliminating the color variations. I was thinking about changing the background color and text color based on what logo that get fetched from the feed. There are only two logo variations. Therefore I thought an If/else statement would do the trick. But I cant get it to work. I need an ELI5 on the solution since I'm pretty new to JS. `

<body onload="choseBG();" id="banner">    

<script>
        function choseBG(){    
            console.log(bgImg);

            if(bgImg = 'assets/NoBorder.png'){
                document.getElementById('banner').style.backgroundColor = '#CCCCCC'
            }else{
                document.getElementById('banner').style.backgroundColor = '#f20403'
            }}
    </script>`

Aucun commentaire:

Enregistrer un commentaire