$(document).ready(function() { /*Initiate the cube css. This must be done in jquery since css is fluid*/
initFluidCubeCSS();
/*Don't touch this! We use global variables to remember the cube's current rotation*/
window.cubescale = 1; //Initial scale is 1.
window.cubeduration = 200; //Initial transition duration is 200ms.
window.cubestate = 2;
/*Bind handler to window for arrow keys to transform the cube*/
$(window).bind('keydown', function(e) {
arrowKeyHandler(e);
});
rotateCube(-90, 90, 0, "same", "same"); //THIS IS THE POSITION THAT HAS PROBLEMS
$('#reset').bind('click', function() {
resetCube();
});
});
function initFluidCubeCSS() {
var cube = $('#cube');
var available_height = $(window).height() - 112; //Calculate the screen height for fluidity.
(available_height > 300) ? cube.css('height', available_height) : cube.css('height', '300px'); //For ux, minimum height for cube is 500px.
var size = cube.css('height');
size = parseInt(size.substring(0, size.length - 2));
/*Style cube & face initial sizes*/
cube.css('width', size + 'px');
cube.children('.face').each(function() {
$(this).css('height', size + 'px').css('width', size + 'px');
});
$('#cubewrapper').css('width', size + 'px');
/*Style each face 3d rotation and z-distance*/
var i = size / 2;
$('#cube > #one').css('-webkit-transform', 'rotateX(90deg) translateZ(' + i + 'px)');
$('#cube > #two').css('-webkit-transform', 'translateZ(' + i + 'px)');
$('#cube > #three').css('-webkit-transform', 'rotateY(90deg) translateZ(' + i + 'px)');
$('#cube > #four').css('-webkit-transform', 'rotateY(180deg) translateZ(' + i + 'px)');
$('#cube > #five').css('-webkit-transform', 'rotateY(-90deg) translateZ(' + i + 'px)');
$('#cube > #six').css('-webkit-transform', 'rotateX(-90deg) translateZ(' + i + 'px)');
}
/*Custom rotateCube method*/
function rotateCube(anglex, angley, anglez,...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.