I have two boxes with 3d transformation (rotationY). Each have almost the same values, one perspective looks fine, the other kinda wrong but still have some correct perspective.
The first box at the top side does not protrude, but it have a perspective view yet. Also the 3° the container is 200% bigger
The second box do a beautiful 3d effect.
Here I made the example of what I'm trying to explain.
$(".eye").on('click', function () {
$( '.man' ).toggleClass('open');
})
* { padding: 0; margin: 0; }
.eye { padding: 6px 8px; }
.universe {
background: rgb(0 0 255 / 0.3);
position: absolute;
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.dark {
background: rgb(0 255 0 / 0.3);
width: 25%;
height: 25%;
}
.god {
background: rgb(255 0 0 / 0.3);
transform-style: preserve-3d;
transform: perspective(800px);
}
.man {
position: absolute;
transform-origin: top left;
transition: 1s all linear;
}
.man.open {
transform: rotateY(-60deg);
}
.life {
background: rgb(255 255 0 / 0.36);
width: 25vw;
height: 25vh;
}
.no.god {
height: 100%;
}
.no.man {
position: relative;
}
.yes.god {
height: 200%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="universe">
<div class="dark">
<div class="god">
<div class="man">
<div class="life">Nothing happens until something moves.</div>
</div>
</div>
</div>
<button class="eye"> OPEN </button>
<div class="dark no">
<div class="god no">
<div class="man no">
<div class="life no">Nothing happens until something moves.</div>
</div>
</div>
</div>
<button class="eye"> OPEN </button>
<div class="dark yes">
<div class="god yes">
<div class="man yes">
<div class="life yes">Nothing happens until something moves.</div>
</div>
</div>
</div>
</div>
I think something is working wrong, but can't figure it out why. Can someone explain me why it's behaving like that?