Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Like show-front, show-top, and so forth. These classes are added to the parent container. In our case, that's the div with the ID of cube, whenever the corresponding thumbnail is clicked. Each class will contain the Transform properties to move the cube side to the front. Let's begin with the front face. So we'll enter in #cube.show-front. Make sure there's no space between cube and the .show-front.
As when we set up the front face for the cube, there's no rotation involved just that translation or movement along the Z axis, whereas previously, the value for the translateZ property was +136 pixels, because we're moving it back into position, we'll use -136 pixels. So let's start with our webkit-transform and the function translateZ of -136 pixels.
Okay, we can copy that line, paste it in three times and change the vendor prefixes as needed. Next, let's turn to the back. Here, and with the rest of the cube sides, we'll perform a rotation as well as a translation, and we'll keep the same values, but make them the inverse of what they were when we set up the cube. So if the values are positive, we'll make them negative, and if they're negative, positive.
And one more thing, if we rotated the cube first and then translate it, we need to do the inverse of that. Then we will need to translate it first so that it's in the proper position to rotate. All right, let's get started with, #cube.show-back. And our first transform property, -webkit-transform. Now let's enter in our translateZ property with a value of -136 pixels, and our other function, rotateX, and we're rotating this 180 degrees, put a semicolon, and this is ready to be copied and pasted, and then slightly modified.
Okay, let's move on. Let's follow the same pattern for the right and left side of the cube. I'll put in my selector for the show-right, starting with webkit-transform and the function translateZ, again, set to -136 pixels, and rotateY -90 degrees. We'll select, copy, and paste as we've done once or twice before.
And now I'm going to copy show-right, and let's paste it in and change it to show-left. The translateZ value we can keep at -136 pixels, but let's change our rotateY from -90 to +90. Finally, let's do the same thing, reversing the signs as it were for the top and bottom of our photo cube. You may face it a little bit faster and maybe a tad less monotonous.
Let's copy the show-right and show-left CSS rules, and then we'll paste them down below and change their names to show-top and show-bottom. The other thing we'll need to change in each of these rules is rotateY to rotateX. Let's save the page, and let's see if we're ready to rock or not. I'll refresh the page in my browser, and let's click through the thumbnails. Sweet! We got a real 3D cube spinning around interactively.
Obviously, this technique is somewhat limited, you can only show six thumbnails and images at a time, but you have to admit, it's a cool addition to get your designer's Toolbox.
Get unlimited access to all courses for just $25/month.Become a member