When the window is not square, you do not have a cube, but a parallelogram.
Your style
<figure class="left" style="width: 227px; height: 402px; -webkit-transform: rotateY(-90deg) translateZ(113.5px);">4 </figure> <figure class="top" style="width: 227px; height: 227px; -webkit-transform: rotateX(90deg) translateZ(113.5px);">5 </figure>
This means that the distance between the top and bottom is 402px (face height).
So, the translation of Z above and below should be half of this (201 px) instead of 113.5 px, as for other sides.
Right now, your upper face is fine, so it might be a better solution, instead of translating the upper and lower 201px, you would translate the lower 402px to 113.5px (face height minus the top translation
Made the following changes:
var bottomTranslate = $(window).height() - cubeWidth; $("#cube .bottom").css({ "-webkit-transform": "rotateX(-90deg) translateZ(" + bottomTranslate + "px)" });
and the result of this
Why does the top panel work?
You take a point in the center of the box, which is the center of the cube, measuring the size of the maximum inner cube and attached to the vertex.
This means that placing the faces at the same distance from the center will work for the side faces (in the vertical projection, the box is a cube); will work on the upper bound (it is assigned so that it works), but will not be executed on the lower bound
Why, when you set the conversion to a cube in Javascript, do the buttons stop working?
Buttons work by setting different classes in a cube div. These classes have precalculated CSS transformations, for example:
#cube.show-right { transform: translateZ(-100px) rotateY(-90deg); }
If you set the transform directly in the cube style, this takes precedence, and changing the class is useless.
Perhaps you could just set the cube sizes (which are set only with javascript) a little less; or change all dynamically applied CSS styles ...