jQuery 弹性缓动方程
我怎样才能修改这个 jQuery 缓动函数以产生不那么夸张的反弹?
$.easing.easeOutElasticSingleBounce = function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
};
我正在寻找一个模拟此的缓动函数:
http://sandbox.scriptiny.com/tinyslider2/< /a>
tinyslider2 使用类似的函数,看起来像这样:
new Function(this.n+'.slide('+(i==1?t+(12*d):t+(4*d))+','+(i==1?(-1*d):(-1*d))+','+(i==1?2:3)+','+a+')')
但我今天似乎无法理解数学以将tinyslider2 方程拟合到 jQuery 缓动格式中。如果有人能给我举一个例子,我将非常感激。
更新
这个等式非常接近:
$.easing.custom = function (x, t, b, c, d) {
var s = 1.70158;
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}
我只需要结束反弹而无需开始反弹。
How can I modify this jQuery easing function to produce a less exaggerated bounce?
$.easing.easeOutElasticSingleBounce = function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
};
I'm looking to produce an easing function that emulates this:
http://sandbox.scriptiny.com/tinyslider2/
tinyslider2 uses a similar function that looks something like this:
new Function(this.n+'.slide('+(i==1?t+(12*d):t+(4*d))+','+(i==1?(-1*d):(-1*d))+','+(i==1?2:3)+','+a+')')
But I can't seem to get my head around the math today to fit tinyslider2 equation into the jQuery easing format. If someone can show me an example, I would appreciate it very much.
UPDATE
This equation is very close:
$.easing.custom = function (x, t, b, c, d) {
var s = 1.70158;
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}
I just need only the ending bounce without the beginning bounce.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://timotheegroleau.com/Flash/experiments/easing_function_generator.htm 让您可以直观地了解创建缓动函数。如果您切换右上角的 F5/FMX 单选按钮,它会以 JavaScript 形式提供输出。
在不知道确切您想要的效果的情况下,这应该会让您非常接近。
否则,请摆弄缓动函数生成器并尝试新选项或查找 http://commadot.com/jquery/ easing.php 获取更多资源。
jsfiddle
http://jsfiddle.net/XRF6J/
这个回答很有趣,我一直想知道如何这些缓和功能发挥了作用。
http://timotheegroleau.com/Flash/experiments/easing_function_generator.htm allows you to visually create an easing function. If you toggle the F5/FMX radio button in the top right, it gives the output in JavaScript.
Without knowing exactly the effect you want, this should get you pretty close.
Otherwise fiddle around with the easing function generator and try new options or look up http://commadot.com/jquery/easing.php for more resources.
jsfiddle
http://jsfiddle.net/XRF6J/
This was fun to answer, I always wanted to find out how those easing functions worked.
您是否尝试过 jQuery 缓动插件?
它添加了许多新的缓动(您可以在网站上尝试)。
如果您可以使用优雅降级,我建议您查看 CSS 转换。它是硬件加速的,您可以使用预定义或自定义(使用贝塞尔曲线)过渡。
Did you try the jQuery easing plugin?
It adds a lot of new easings (you can try them on the website).
If you can use graceful degradation, I suggest you to take a look at CSS transitions. It’s hardware accelerated, and you can use predefined or custom (with a bezier curve) transitions.
我知道这已经很老了,但我需要做出完全相同的效果,并且我在 UI 中非常成功地使用了两个缓动函数的组合。
在 95% 的“时间”处实现 95% 的过渡的线性动画,然后在 5% 的“时间”乘以 16 处对剩余 5% 的过渡进行弹性动画(这看起来似乎是正确的 - 很多动画此效果的时间专门用于弹跳,因此需要相当长的时间)。
这确实是一个解决方法,但我无法创建贝塞尔曲线公式,而且我正在努力尝试。
I know this is pretty old, but I needed to make the exact same effect and I used a combination of two easing functions in UI quite successfully.
A linear animation for 95% of the transition at 95% of the 'time', then an elastic animation over the remaining 5% at 5% of the 'time' times 16 (this just seemed to look right - a lot of the animation time for this effect is devoted to bouncing around so it needs to be considerably longer).
Quite the workaround, but I couldn't create a bezier formula and I was tearing my hair out trying.