Instructor: Here I have my transforms.html file. It contains three sections with each section having a title, a button, and an image of a cat.
We're going to add three transition functions to the elements on this page. The first transition we'll add is translateX. This moves an element horizontally. When we click the button, a new class, translateX, will be appended to the cat image node.
Let's go ahead and add a translateX of a 100 pixels. When we click the button, we can see that the cat moves 100 pixels. When we click it again to reset it, it jumps back. This is because we're appending and removing the translateX class name from the image node.
This transformation was a bit sudden, so let's add a transition function. Transition functions make your animations more fluid. They take the CSS property you want to transition, the length of the transition, and the timing function. For our timing function, we'll use ease-in, which starts out slowly and gets faster as the animation progresses.
Now let's translate the Y-image. This will follow the same process as X-translation. First, we'll add the transform with the translateY a 50 pixels.
Now let's add the transition function on the image. This time, we'll use ease-out, which starts out fast and decelerates as the animation's coming to an end. Now when we click the translateY button, the cat moves down and up.
We can also transform with the X- and Y-values simultaneously by using the translate shortcut. This takes the X-transition value first and then the Y-transition value second.
Finally, we'll add a transition function of linear, which maintains the same speed throughout the entire transition. When we click the button, the cat moves down and to the right. That's it. Now you know how to use the translate functions.