I am trying to create a gallery on my website and I have them all set to increase in size when hovered over. The only issue is even when they increase in size, the images beside them show on top of the increased image.
Here is the HTML:
<div class="flex-con-col" style="align-content: space-around;">
<div class="flex-con-row" style="align-content: space-around">
<div>
<img src="img/socialBar.jpg" alt="" onmouseover="bigImg('galImg1')" onmouseout="normalImg('galImg1')" id="galImg1" style="height: 200px;"/>
</div>
<div style="width: 20px;"></div>
<div>
<img src="img/outside.jpg" alt="" onmouseover="bigImg('galImg2')" onmouseout="normalImg('galImg2')" id="galImg2" style="height: 200px;"/>
</div>
<div style="width: 20px;"></div>
<div>
<img src="img/socialBar2.jpg" alt="" onmouseover="bigImg('galImg3')" onmouseout="normalImg('galImg3')" id="galImg3" style="height: 200px;"/>
</div>
<div style="width: 20px;"></div>
<div>
<img src="img/socialBar.jpg" alt="" onmouseover="bigImg('galImg4')" onmouseout="normalImg('galImg4')" id="galImg4" style="height: 200px;"/>
</div>
</div>
</div>
Here is my script:
<script>
function bigImg(id) {
img = document.getElementById(id);
img.style.transform = "scale(2)";
img.style.transition = "transform 0.25s ease";
img.style.zIndex = "99";
}
function normalImg(id) {
img = document.getElementById(id);
img.style.transform = "scale(1)";
img.style.transition = "transform 0.25s ease";
img.style.zIndex = "1";
}
</script>
Here is my CSS:
.flex-con-row {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: center;
align-items: center;
}
.flex-con-col {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: center;
align-items: center;
}
I tried to increase and decrease the z-index, thinking that would help. But no such luck.
**** EDIT **** I solved the issue. Leaving the question up here for future people to view. In the javascript, I had to set the div to change z-index, not the picture itself. Solution:
<script>
function bigImg(id) {
img = document.getElementById(id);
par = img.parentNode;
img.style.transform = "scale(2)";
img.style.transition = "transform 0.25s ease";
par.style.zIndex = 99;
}
function normalImg(id) {
img = document.getElementById(id);
par = img.parentNode;
img.style.transform = "scale(1)";
img.style.transition = "transform 0.25s ease";
par.style.zIndex = 1;
}
</script>