I am trying to create a transition that moves a white div on top of an image. I can do that with ONE image currently, however, I would like to be able to do this with two or more images…
I think the issue has something to do with the position property here, but I am not sure what the actual solution would be.
Here is a codepen: https://codepen.io/jon424/pen/XWzGNLe When you click “toggle”, you will see the transition happen over the first image, but I would like the same thing to happen over the second image at the same time. Any idea how to do this?
HTML
<button>Toggle</button>
<div class="parent">
<img class="child1" src="https://picsum.photos/200/300">
<div class="child1 covering"></div></div>
<div class="parent">
<img class="child2" src="https://picsum.photos/200/302">
<div class="child2 covering"></div></div>
CSS
.parent {
position: relative;
width: 300px;
height: 300px;
margin: 10px;
}
.child1 {
position: absolute;
width: 100%;
height: 100%;
bottom: 0;
left: 0;
}
.child2 {
/* position: absolute; */
width: 100%;
height: 100%;
bottom: 0;
left: 0;
}
.covering {
z-index: 1;
background: #ffffff;
transition: max-height 1s ease-in-out;
max-height:100%;
}
.covered {
max-height: 0px;
}
.hidden {
display: none;
}
JS
const firstTarget = document.querySelector(".firstTarget");
const covering = document.querySelector(".covering");
document.querySelector('.covering').classList.add('covered');
document.querySelector('button').addEventListener('click', () => { document.querySelector('.covering').classList.toggle('covered');});