我正在寻找可以与 jQuery 一起使用的自定义缓动函数的在线列表。
我对使用插件不感兴趣,也不使用 jQuery UI。
我发现下面的一个可以产生不错的小反弹,但我正在寻找其他一些,这样我就可以有一些选择。
代替其他功能,简要解释该功能如何运行以及可能如何修改将是很棒的。谢谢你!
示例:
$.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;
}
编辑 #1:
这是所有 jQuery UI 缓动函数的在线演示。来自 UI 的源函数在下面由 Jake 的正确答案中发布。
http://api.jqueryui.com/easings/
编辑#2:
事实证明,我上面发布的示例缓动函数与 jQuery UI 中的“easeInOutBack”完全相同。
编辑 #3:
这里有一些更多独立的缓动方程可供免费下载...
http://www.robertpenner.com/easing/
I'm looking for an online list of custom easing functions that I can use with jQuery.
I'm not interested in using a plugin for this, nor am I using jQuery UI.
I found one below that does a nice little bounce but I'm looking for a few others just so I can have some options.
In lieu of of other functions, a brief explanation of how this one operates and might be modified would be awesome. Thank-you!
Example:
$.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;
}
EDIT #1:
Here's an online demo of all jQuery UI easing functions. Source functions from UI are posted below in correct answer by Jake.
http://api.jqueryui.com/easings/
EDIT #2:
It turns out that the example easing function I posted above is exactly the same as the "easeInOutBack" from jQuery UI.
EDIT #3:
Here are some more stand-alone easing equations free for downloading...
http://www.robertpenner.com/easing/
发布评论
评论(4)
如果您遵循 BSD 许可条款,您可以直接从 jQuery UI 源代码中挑选您想要的缓动函数。请注意,其中一些函数依赖于列表中的其他函数。
要查看和比较这些缓动函数的实际效果,请参阅:http://api.jqueryui.com/easings/
Provided that you follow the BSD licensing provisions, you can cherry-pick the easing functions that you want directly from the jQuery UI source code. Note that some of these functions depend on other functions within the list.
To view and compare these easing functions in action, see: http://api.jqueryui.com/easings/
用法:
将以下内容完全按照原样粘贴到 javascript 文件的底部。然后,按照上面的说明,就像安装了 jQueryUI 一样使用。
来源:
http://gsgd.co.uk/sandbox/jquery/easing/
Usage:
Paste the following in at the bottom of your javascript file, exactly as is. Then, use as if jQueryUI was installed, as per above.
Source:
http://gsgd.co.uk/sandbox/jquery/easing/
对于任何使用 Webpack 等打包程序来捆绑服务器渲染资产的人来说,我遇到了
Error: TypeError: _jquery2.default.extend is not a function
错误 (参考)。我可以通过使用Object.assign()
而不是$.extend
来解决这个问题:For anyone using a packager like Webpack to bundle server-rendered assets, I encountered a
Error: TypeError: _jquery2.default.extend is not a function
error (reference). I was able to get around this by usingObject.assign()
instead of$.extend
:jquery 有 bez 插件 ( http://github.com/rdallasgray/bez ),它可以让你创建自定义贝塞尔曲线缓动函数。
如果您想摆弄 4 个贝塞尔曲线参数,这里有一个在线工具,您可以轻松获取所需的参数:http: //cubic-bezier.com
这是代码
There is the bez plugin for jquery ( http://github.com/rdallasgray/bez ) which lets you create custom bezier easing functions.
If you want to fiddle around with the 4 bezier parameters, here is a online tool, where you can easily get the desired params: http://cubic-bezier.com
Here's the code