Cube thingy
How do I make an cube thingy?
Rotate cube using arrow keys. What is a cube thingy? How do you make a cube thingy? This script and codes were developed by Teo Dragovic on 05 January 2023, Thursday.
Cube thingy - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Cube thingy</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ * { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
html { height: 100%;
}
body { background-image: radial-gradient(#333333, #1a1a1a); overflow: hidden; height: 100%; font-family: sans-serif;
}
.container { position: relative; margin: 100px auto; width: 200px; height: 200px; perspective: 1000px;
}
.cube { position: absolute; width: 100%; height: 100%; transition: transform 1s; transform-style: preserve-3d;
}
.cube .side { position: absolute; display: block; width: 100%; height: 100%; backface-visibility: hidden; box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.2);
}
.cube .side.blue { background-image: radial-gradient(#4a5096, #393e74);
}
.cube .side.pink { background-image: radial-gradient(#944a67, #72394f);
}
.cube .side.aqua { background-image: radial-gradient(#4a8994, #396a72);
}
.cube .side.green { background-image: radial-gradient(#4a944c, #39723b);
}
.cube .side.orange { background-image: radial-gradient(#94764a, #725b39);
}
.cube .side.red { background-image: radial-gradient(#944a4a, #723939);
}
.cube .side.front { transform: rotateX(0deg) translateZ(100px);
}
.cube .side.back { transform: rotateX(180deg) translateZ(100px);
}
.cube .side.right { transform: rotateY(90deg) translateZ(100px);
}
.cube .side.left { transform: rotateY(-90deg) translateZ(100px);
}
.cube .side.top { transform: rotateX(90deg) translateZ(100px);
}
.cube .side.bottom { transform: rotateX(-90deg) translateZ(100px);
}
p { width: 100%; color: #555; text-align: center; line-height: 1.5;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div class="container"> <div id="cube" class="cube"> <div class="side blue front"></div> <div class="side pink back"></div> <div class="side aqua right"></div> <div class="side green left"></div> <div class="side orange top"></div> <div class="side red bottom"></div> </div>
</div>
<p>rotate cube using arrow keys<p> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Cube thingy - Script Codes CSS Codes
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
html { height: 100%;
}
body { background-image: radial-gradient(#333333, #1a1a1a); overflow: hidden; height: 100%; font-family: sans-serif;
}
.container { position: relative; margin: 100px auto; width: 200px; height: 200px; perspective: 1000px;
}
.cube { position: absolute; width: 100%; height: 100%; transition: transform 1s; transform-style: preserve-3d;
}
.cube .side { position: absolute; display: block; width: 100%; height: 100%; backface-visibility: hidden; box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.2);
}
.cube .side.blue { background-image: radial-gradient(#4a5096, #393e74);
}
.cube .side.pink { background-image: radial-gradient(#944a67, #72394f);
}
.cube .side.aqua { background-image: radial-gradient(#4a8994, #396a72);
}
.cube .side.green { background-image: radial-gradient(#4a944c, #39723b);
}
.cube .side.orange { background-image: radial-gradient(#94764a, #725b39);
}
.cube .side.red { background-image: radial-gradient(#944a4a, #723939);
}
.cube .side.front { transform: rotateX(0deg) translateZ(100px);
}
.cube .side.back { transform: rotateX(180deg) translateZ(100px);
}
.cube .side.right { transform: rotateY(90deg) translateZ(100px);
}
.cube .side.left { transform: rotateY(-90deg) translateZ(100px);
}
.cube .side.top { transform: rotateX(90deg) translateZ(100px);
}
.cube .side.bottom { transform: rotateX(-90deg) translateZ(100px);
}
p { width: 100%; color: #555; text-align: center; line-height: 1.5;
}
Cube thingy - Script Codes JS Codes
var xAngle = 0, yAngle = 0, zAngle = 0, cube = $("#cube");
$(document).keydown(function(e) { //keyup maybe better? e.preventDefault(); var key = e.which, arrow = {left: 37, up: 38, right: 39, down: 40}, x = xAngle/90, y = yAngle/90; switch(key) { case arrow.left: if (x%2 == 0) yAngle -= 90; else zAngle += 90; break; case arrow.up: if (y%2 == 0) xAngle += 90; else zAngle -= 90; break; case arrow.right: if (x%2 == 0) yAngle += 90; else zAngle -=90; break; case arrow.down: if (y%2 == 0) xAngle -= 90; else zAngle += 90; break; } var rotate = "rotateX(" + xAngle + "deg) rotateY(" + yAngle + "deg) rotateZ(" + zAngle + "deg)"; cube.css({"transform":rotate});
});
/*
Reference material:
https://desandro.github.io/3dtransforms/docs/cube.html
http://www.paulrhayes.com/2009-07/animated-css3-cube-interface-using-3d-transforms/
https://blog.joelambert.co.uk/2011/05/10/handling-3d-geometry-with-3d-css3-transforms/
+ CSS-Tricks and Stack Overflow for random shit
*/
Developer | Teo Dragovic |
Username | teodragovic |
Uploaded | January 05, 2023 |
Rating | 3 |
Size | 3,988 Kb |
Views | 4,048 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Sticky sidebar thingy | 3,068 Kb |
Origami boat | 3,030 Kb |
Client logo done in css | 2,273 Kb |
Galaxy sky thingy | 5,556 Kb |
Dice | 4,311 Kb |
Knob thingy | 6,696 Kb |
3D letter thingy | 3,589 Kb |
Responsive nav with submenus | 4,273 Kb |
A Pen by Teo Dragovic | 2,756 Kb |
Page load thingy | 3,146 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Tooltip in table | Roine | 3,713 Kb |
Factorial | KeithleySLHS | 1,158 Kb |
Material Design-Layout-Principles Practice | Fraina | 2,331 Kb |
Sidebar Thing | Jonambas | 2,779 Kb |
Gears | Synvox | 3,278 Kb |
CSS Dynamic Width Square Div | Elleestcrimi | 2,861 Kb |
CSS3 Media Queries demo | Machal | 1,824 Kb |
Hello People | Danburrows | 2,365 Kb |
Scroll effect with text with help from Skrollr | Luxonglassing | 2,935 Kb |
DevCamp 2014 - Denver Public Library | See8ch | 5,033 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!