16 Transforms

 

This chapter covers

  • Manipulating elements using transforms for performant transitions and animations
  • Adding a bounce effect to a transition
  • The browser’s rendering pipeline and performance considerations
  • 3D transforms and perspective

In this chapter, we’ll explore the transform property, which you can use to change or distort the shape or position of an element on the page. This can involve rotating, scaling, or skewing the element in two or three dimensions. Transforms are most commonly used in conjunction with transitions or animations, which is why I’ve sandwiched this chapter between those two topics. In these last two chapters, you’ll build a page that makes heavy use of transitions, transforms, and animations.

First, I’ll walk you through applying transforms to a static element. This will give you a grasp of how they work in isolation before you add them into some transitions. Then, you’ll build a small but complex menu with multiple transforms and transition effects. Finally, we’ll take a look at working in 3D and utilizing perspective. This will carry over into the next chapter, where you’ll use 3D transforms in conjunction with animation.

16.1 Rotate, translate, scale, and skew

A basic transform rule looks something like this:

transform: rotate(90deg);

16.1.1 Changing the transform origin

16.1.2 Applying multiple transforms

16.1.3 Individual transform properties

16.2 Transforms in motion

16.2.1 Scaling up the icon

16.2.2 Creating “fly in” labels

16.2.3 Staggering the transitions

16.3 Animation performance

16.3.1 Looking at the rendering pipeline

16.4 3D transforms

16.4.1 Controlling perspective

16.4.2 Implementing advanced 3D transforms

Summary