CSS: Transitions and Transforms
Illustration by John Hersey

Animating the image cube


From:

CSS: Transitions and Transforms

with Joseph Lowery

Video: Animating the image cube

In the previous movie, creating an image cube, we set up the initial CSS rules necessary for transforming--there's that word again--two-dimensional pictures into a three-dimensional cube. In this movie we're going to add the necessary JavaScript and CSS3 rules to make it interactive. First, let's bring in our JavaScript helpers. In all there are three files we're going to link to. Let's start with Modernizer, the excellent library that makes it easy to detect the CSS browser support on the function by function basis.

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course CSS: Transitions and Transforms
2h 25m Intermediate Jul 11, 2012

Viewers: in countries Watching now:

With robust and ever-increasing browser support, it is now possible to take advantage of expressive CSS3 capabilities across modern browsers. In this course, Joseph Lowery explores the possibilities of the new coding options, which animate well over 50 different properties automatically or interactively, and how they open the door to enhanced user experiences. This course covers the range from simple to complex transitions, including 2D and 3D transforms, and illustrates how transitions are expedited in various web authoring tools, as well as Dreamweaver. The course also contains a start-to-finish interactive slideshow project that allows you to practice and see the transitions and transforms immediately in action.

Topics include:
  • Understanding transition basics
  • Working with 2D and 3D transforms
  • Animating color changes
  • Fading objects
  • Changing the size of page elements and fonts
  • Transitioning multiple properties at the same time
  • Understanding keyframes and animations
  • Working in the z-index
  • Adding JavaScript interactivity
  • Crafting transitions in Dreamweaver
Subject:
Web
Software:
CSS
Author:
Joseph Lowery

Animating the image cube

In the previous movie, creating an image cube, we set up the initial CSS rules necessary for transforming--there's that word again--two-dimensional pictures into a three-dimensional cube. In this movie we're going to add the necessary JavaScript and CSS3 rules to make it interactive. First, let's bring in our JavaScript helpers. In all there are three files we're going to link to. Let's start with Modernizer, the excellent library that makes it easy to detect the CSS browser support on the function by function basis.

So right after the second link tag that links our CSS Transition file, we'll add in the script tag, set the type to text/javascript, and source will set to the _scripts folder, and within that, modernizr 2.5.3.min.js. Let's close out the script tag, and we'll go to our next line.

Next I'm going to link to a series of utilities, put together by David DeSandro whose Tutorial on 3D cubes was the basis for this implementation. Again, the script, type text/javascript, and the source. We will go again to my _scripts folder, and this time it's utils.js. One more to go, and the final one is the rotate.js file, also scripted by David DeSandro that handles the actual CSS class removal, and addition, when the thumbnail is clicked.

So we start it with the script, type, and again it's text/javascript, and we'll point to the same path which is our . ./_scripts/rotate-box.js. That's all of the JavaScript, I'm going to save the page. Let's turn to the remaining CSS rules. All that's left to do is to add the rules that govern the show classes.

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.

There are currently no FAQs about CSS: Transitions and Transforms.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS: Transitions and Transforms.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.