I got a fixed div that follows you when you scroll on the side of my screen, I would like to change it's background based on it's current background. So for example when the div is on a white background it's set to background-color: gray
and when its on a gray background it would be background-color: white
Also I want it to change the color when you sroll over another background color, not with a button that you need to click when trying to change the color.
I made a little example down here:
.background1{
background-color: #777777;
height: 300px;
width: 100%;
padding: 50px 200px;
box-sizing: border-box;
}
.background2{
background-color: #444444;
height: 300px;
width: 100%;
padding: 50px 200px;
box-sizing: border-box;
}
.background3{
background-color: #dddddd;
height: 300px;
width: 100%;
padding: 50px 200px;
box-sizing: border-box;
}
.background4{
background-color: #bbbbbb;
height: 300px;
width: 100%;
padding: 50px 200px;
box-sizing: border-box;
margin-bottom: 500px;
}
.example-color1{
color: white;
font-weight: bold;
background-color: #444444;
width: 100px;
height: 100px;
padding: 10px;
}
.example-color2{
color: white;
font-weight: bold;
background-color: #cccccc;
width: 100px;
height: 100px;
padding: 10px;
}
.example-color3{
color: white;
font-weight: bold;
background-color: #666666;
width: 100px;
height: 100px;
padding: 10px;
}
.example-color4{
color: white;
font-weight: bold;
background-color: #999999;
width: 100px;
height: 100px;
padding: 10px;
}
.fixed-background{
position: fixed;
top: 55px;
left: 30px;
background-color: white;
height: 100px;
width: 100px;
border: 1px black solid;
padding: 10px;
}
<div class="background1"><div class="example-color1">For example this color on this block</div></div>
<div class="background2"><div class="example-color2">For example this color on this block</div></div>
<div class="background3"><div class="example-color3">For example this color on this block</div></div>
<div class="background4"><div class="example-color4">For example this color on this block</div></div>
<div class="fixed-background">This should change color based on background</div>