I have multiple images on top of each other. They are almost the same, only some parts are different. I want to make a transition effect between the two, so that the new parts appear and the old parts disappear, but most of the image (the static parts) stay the same.
I did that with moving the opacity of the new image from 0 to 1 and the old image from 1 to 0. They add up to 1, but they still produce a different color.
I've made a fiddle to demonstrate this: https://jsfiddle.net/sashee/r740snug/1/ . Here, there are two red boxes and they overlap. They both have opacity: 0.5, so I'd assume the overlap renders as true red. But notice the third box, below the other two that has no opacity and its color is clearly different from the overlapped area.
<div
class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
.box1{
position: absolute;
width: 100px;
height: 100px;
background-color: red;
opacity: 0.5;
}
.box2{
position: absolute;
left: 50px;
width: 100px;
height: 100px;
background-color: red;
opacity: 0.5;
}
.box3{
position: absolute;
top: 100px;
width: 100px;
height: 100px;
background-color: red;
}
I couldn't find any information how opacity should work and how should I set the different elements' opacities to visually add up to 1. Is there a way to have 2 elements on top of each other with some opacity values and they add up to a color that is the same as having opacity:1?