我正在尝试将自己的函数传递给jquery动画来创建自己的缓动函数。此代码是用coffeescript编写的,实际上是调用的,但不执行缓动函数。它只是像回调函数一样。还有其他人经历过这个吗?
easing : (x, t, b, c, d) ->
if ((t/=d) < (1/2.75))
return c*(7.5625*t*t) + b
else if (t < (2/2.75))
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b
else if (t < (2.5/2.75))
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b
else
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b
show : () =>
@container.slideDown @config.animationTime, @easing(), () =>
@config.visible = true
答案 0 :(得分:1)
来自fine manual:
从jQuery 1.4.3开始,可以使用命名缓动函数的可选字符串。
因此easing
参数应该是一个字符串,用于命名要使用的缓动,而不是缓动函数本身。此外,这是一个方法调用:
@easing()
虽然这是对您的缓动功能的引用:
@easing
如果要定义自定义缓动,则必须通过向$.easing
添加属性来全局执行:
$.easing.whatever = (x, t, b, c, d) ->
#...
然后按名称引用它:
@container.slideDown @config.animationTime, 'whatever', () => ...