{"id":280052,"date":"2018-12-17T08:12:13","date_gmt":"2018-12-17T15:12:13","guid":{"rendered":"http:\/\/css-tricks.com\/?p=280052"},"modified":"2018-12-17T08:12:13","modified_gmt":"2018-12-17T15:12:13","slug":"reversing-an-easing-curve","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/reversing-an-easing-curve\/","title":{"rendered":"Reversing an Easing Curve"},"content":{"rendered":"

Let\u2019s take a look at a carousel I worked on where items slide in and out of view with CSS animations. To get each item to slide in and out of view nicely I used a cubic-bezier for the animation-timing-function<\/code> property, instead of using a standard easing keyword.<\/p>\n

<\/p>\n

See the Pen Carousel with reversed easing curve<\/a> by Michelle Barker (@michellebarker<\/a>) on CodePen<\/a>.<\/p>\n

A cubic-bezier can appear confusing at first glance, but when used correctly, it can add a nice touch to the user experience.<\/p>\n

While building this carousel, I realized I not only needed a custom animation curve, but had to use it in reverse as well to get the effect right. I figured it was worth sharing what I learned because creating a custom curve and reversing it may seem tricky, but it\u2019s actually pretty straightforward.<\/p>\n

First, a primer on easing<\/h3>\n

Easing<\/a> is the word used to describe the acceleration and deceleration of an animation\u2019s progress along a timeline. We can plot this as a graph, where x<\/strong> is time and y<\/strong> is the animation\u2019s progress. The graph for a linear animation, which has no acceleration or deceleration (it moves at the same speed all the way through), is a straight line:<\/p>\n

\"Linear<\/figure>\n

Non-linear easing is what gives animations a more natural, life-like feel. We can apply easing to transitions and animations in CSS. The animation-timing-function<\/code><\/a> property allows us to define the easing on an animation. (The same options are available for transition-timing-function<\/code><\/a>.) We have four keywords to choose from:<\/p>\n