$(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);
});
});
/*Custom rotateCube method*/
function rotateCube(anglex, angley, anglez, scale, duration) {
var cube = $('#cube'); /*Scale for cube to be drawn*/
var oldMatrix = new WebKitCSSMatrix(cube[0].style.webkitTransform);
var extrarotate = (new WebKitCSSMatrix()).rotate(anglex, angley, anglez);
var final = extrarotate.multiply(oldMatrix);
var finalstring = [];
for (var i = 1; i < 5; i++) {
for (var j = 1; j < 5; j++) {
finalstring.push(Math.round(final['m' + i + j]));
}
}
cube[0].style.webkitTransform = 'matrix3d(' + finalstring.join(',') + ')';
}
function arrowKeyHandler(e) {
//$(window).unbind('keydown');
var xAngle = 0;
var yAngle = 0;
var zAngle = 0;
var xPos = 0;
var yPos = 0;
var zPos = 0;
switch (e.keyCode) {
case 38:
//up
xAngle = 90;
yPos = 100;
break;
case 40:
//down
xAngle = -90;
yPos = -100;
break;
case 37:
//left
yAngle = -90;
xPos = -100;
break;
case 39:
//right
yAngle = 90;
xPos = 100;
break;
}
if (yAngle != 0 || xAngle != 0 || zAngle != 0) rotateCube(xAngle, yAngle, zAngle, "same", "same");
}
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.