如何调用我自己的自定义缓动形状?

时间:2014-11-14 11:55:18

标签: jquery easing

这是我的动画:

elem.animate({ left: stepLeft + "px" }, timing, "MyOwnEasingFunction", function () {
    // somethings
});

我想用我自己的函数替换MyOwnEasingFunction,它使用这个缓动:

$.easing.bw = function(x, t, b, c, d) {
    ts=(t/=d)*t;
    tc=ts*t;
    return b+c*(25.8*tc*ts + -78.5*ts*ts + 89.6*tc + -47.4*ts + 11.50*t);   
}

但我怎么称呼它?

2 个答案:

答案 0 :(得分:1)

查看jQuery easing function — variables' comprehension,它将采用以下格式

$.extend(jQuery.easing,{MyOwnEasingFunction:function(x, t, b, c, d) {
    ts=(t/=d)*t;
    tc=ts*t;
    return b+c*(25.8*tc*ts + -78.5*ts*ts + 89.6*tc + -47.4*ts + 11.50*t);   
}});

elem.animate({ left: stepLeft + "px" }, timing, "MyOwnEasingFunction", function () {
   // somethings
});

在这里小提琴:http://fiddle.jshell.net/mme7dhx8/

答案 1 :(得分:0)

elem.animate({ left: stepLeft + "px" }, timing, function(x, t, b, c, d) {
        ts=(t/=d)*t;tc=ts*t;return b+c*(25.8*tc*ts + -78.5*ts*ts + 89.6*tc + -47.4*ts + 11.50*t);   
    }, function () {
        // somethings
    });