Html5 CSS3 3D Cube
For a while I have been experimenting with creating 3D objects in a regular web browser without resorting to plugins such as Flash, Silverlight etc. The Cube shown here is adapted from another 3D website I made earlier.
WebGL enables us to render complex 3D models in a browser. However, here I will be looking at creating a 3D object using the various CSS3 transform commands that can take a regular 2D Html element and project it into 3D space.
The advantage of using 3D transforms on regular Html elements is you can project things like Iframe content, images or any other html element into 3D creating some really neat effects.
Here is a sample of the cube using some images and text. You can use the mouse to spin the cube.
As the 3D cube shown here uses CSS3 Matrix Transforms rather than the plain Rotate, Scale, Translate methods used by some other 3D Cubes, it works well in IE11. As well as IE11, it has been tested in Firefox, Chrome, Safari and Mobile Safari for iOS.
The important bit here is we include the "Cube.js" file. We also need JQuery, that is included as well.
The Div with the ID my3Dsurface will contain our 3D cube. Notice the data-facewidth="256" attribute. This specifies the size of our cube faces.
Next we create an instance of Js3DSurface and pass it an array of content that will be displayed on each face of our cube. In this example we are using images and simple html content. You can add more complex html such as Iframes, Video tags etc.
We also add 3 event handlers to enable us to spin the cube using the mouse. When the mouse moves with the left mouse button down, we call adjRot passing it the new X and Y position of the mouse.
Grab the sample code yourself from the link below and start creating cool 3D project Html cubes!
Click the link below to download the file(s):
3D Cube in Css3: 3dCss3.zip (141.27kb)