How to implement easeOutBack easing in css transform animation

11,341

Solution 1

You can specify your own curve with the -webkit-animation-timing-function CSS property.

The format of the function is cubic-bezier(P1x, P1y, P2x, P2y) where P1 and P2 are the two middle points of a cubic bezier curve from (0,0) to (1,1). In your case you want something that looks like -

EaseOutBack http://i56.tinypic.com/adg8yo.png

So the points you would specify in this curve are - (0,0) and (0.2,1). This makes the curve - cubic-bezier(0,0,0.2,1).

Alas, the webkit cubic curve specification does not allow the animation to exceed the bounds of 1,1 cube. So to actually animate the curve as desired you need to add an extra keyframe that specifies the 'overflow'.

@-webkit-keyframes snapback {
    0% {
        -webkit-transform:translateX(0px);
    }
    60% {
        -webkit-transform:translateX(140px);
    }
    100% {
        -webkit-transform:translateX(100px);
    }
}

Take a look at the example I threw together - http://jsfiddle.net/Heqs8/

Solution 2

Looks like the following code will add the easeOutBack animation to jQuery, and then you should be able to use it.

jQuery.extend(jQuery.easing, {
    easeOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
    }
});

Found from http://jsfiddle.net/marcofucci/rRtAq/ which mentions http://gsgd.co.uk/sandbox/jquery/easing/.

Solution 3

Another alternative is the CSS3 Animation Generator, which enables 12 easing functions not supported by the W3C specifics, including back-ease-out. Rather than using cubic curves, which has a number of limitations, the CSS3 Animation Generator uses calculated keyframes.

Share:
11,341
WaiLam
Author by

WaiLam

Chef Developer in Digicrafts (www.digicrafts.com.hk/components). Love programming. Work with JS, ActionScript, Objective-C....

Updated on June 07, 2022

Comments

  • WaiLam
    WaiLam almost 2 years

    I am working with some css animation. But I found that, the CSS transition only support following easing function.

    ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier()

    I do want to use something like easeOutBack easing in the animation with pure css. I am thinking to do it with the webkit-animation. But only safari support it.

    The easeOutBack motion is a motion where the object will go beyond the boundary and back again.More about different motion function. You can see this link below.

    http://hosted.zeh.com.br/tweener/docs/en-us/misc/transitions.html

    Anyone have suggestion of how to implement easeOutBack easing in css transform animation?

    • Mamey
      Mamey about 13 years
      it might help if your explain what easeOutBack means. not everyone uses the jquery module you're referring to.
    • WaiLam
      WaiLam about 13 years
      Sorry, i have add some explanation.
  • WaiLam
    WaiLam about 13 years
    Thanks. But I want to use pure CSS animation but not jquery.
  • Chris McFarland
    Chris McFarland about 13 years
    Tagging your question with jQuery tags is a bit confusing then.
  • WaiLam
    WaiLam about 13 years
    The tag is not added by me. i will remove it.
  • WaiLam
    WaiLam almost 13 years
    Great..i also try to implement the animation like this. But webkit only. I am trying to hack jquery animation module to support css3 transform. So, i can make use of jquery timing function + css transform to achieve the results.
  • Steven Lu
    Steven Lu about 12 years
    While the animation does go past the target point and returns to the target point it is only C0 continuous and looks entirely unconvincing. You want to keep the motion smooth so use ease-in on the first segment and ease-out on the second segment, and ease-in-out on the last one.
  • Steven Lu
    Steven Lu about 12 years
    Well -- ease-in-out on the last one doesn't look good either. There's gotta be a good bezier function for it.