简体   繁体   English

jQuery.easing-easeOutCubic-强调易用性

[英]jQuery.easing - easeOutCubic - emphasizing on the ease

I'm using the jQuery easing plugin by Robert ( http://gsgd.co.uk/sandbox/jquery/easing/ ) and I need to emphasizing or drag out the ease effect. 我使用的是罗伯特( http://gsgd.co.uk/sandbox/jquery/easing/ )的jQuery轻松插件,我需要强调或拖延轻松效果。

Basically, I want the ease effect to be really quick but then slow down greatly during the ease out. 基本上,我希望缓动效果真的很快,但在缓动过程中却大大放慢。

I believe I can do this using jQuery.easing.easeOutCubic( null, current_time, start_value, end_value, total_time) but I can't figure out how to use it properly. 我相信我可以使用jQuery.easing.easeOutCubic( null, current_time, start_value, end_value, total_time)来做到这jQuery.easing.easeOutCubic( null, current_time, start_value, end_value, total_time)但我不知道如何正确使用它。

How can this be achieved? 如何做到这一点?

You do not need an easing plugin to do custom easing with jQuery. 您无需使用缓动插件即可使用jQuery进行自定义缓动。 You only need the source JavaScript code of the one easing function you are going to use. 您只需要要使用的一个缓动函数的源JavaScript代码。

Here is the easeOutCubic function obtained from the jQuery UI source code. 这是从jQuery UI源代码获得的easeOutCubic函数。 See this thread for more . 有关更多信息,请参见此线程

$.easing.easeOutCubic = function (x, t, b, c, d) {
    return c*((t=t/d-1)*t*t + 1) + b;
}

Now you can edit the function and/or rename it... 现在您可以编辑功能和/或重命名...

$.easing.myEasing = function (x, t, b, c, d) {
    return c*((t=t/d-1)*t*t + 1) + b;
}

(All of the following examples use a 375 pixel blue square with a slideToggle() of 3 second duration. You can alter the 3 seconds (3000 ms) duration to demonstrate the effect to your liking. I chose 3 seconds to make it slow enough to see the differences.) (以下所有示例均使用375像素的蓝色正方形,其slideToggle()的持续时间为3秒。您可以更改3秒(3000毫秒)的持续时间来演示自己喜欢的效果。我选择了3秒以使其足够慢以查看差异。)

Then you just put it inside your jQuery, something like this perhaps... 然后,您只需将其放在jQuery中,也许像这样……

$(document).ready(function(){

        $.easing.myEasing = function (x, t, b, c, d) {
            return c*((t=t/d-1)*t*t + 1) + b;
        }

        $("#button").click(function() {
            $('#myDiv').slideToggle(
                3000, // <-- Animation Duration (3000 ms)
                'myEasing'  // <-- the Name of your easing function
            );
        });

});

Here is a demo of the above code which contains the easeOutCubic function renamed as myEasing and applied to a slideToggle() cube with a 3 second duration. 这是上述代码的演示,其中包含更名为myEasingeaseOutCubic函数,并以3秒的持续时间将其应用于slideToggle()多维数据集。

http://jsfiddle.net/kJZxQ/ http://jsfiddle.net/kJZxQ/

Ok, now to your issue: You said that you want "...the ease effect to be really quick but then slow down greatly during the ease out." 好了,现在您的问题是:您说您希望“ ...缓解效果确实很快,但是在缓解期间会大大降低。”

Here is a graph of easeOutCubic : 这是easeOutCubic的图形: 三次立方

You have two options, you can manipulate the easing equation itself or we can see if some other easing function has a similar curve, but steeper (faster) until the ease out part. 您有两个选择,您可以操纵缓动方程本身,或者我们可以查看其他缓动函数是否具有相似的曲线,但在缓动部分之前更陡峭(更快)。

This demo page visually shows you all the easing curves... 该演示页面直观地显示了所有缓动曲线...

http://api.jqueryui.com/easings/ http://api.jqueryui.com/easings/

As you can see, several curves are shaped similarly to (7)- easeOutCubic yet are steeper on the front end. 如您所见,多条曲线的形状类似于(7) easeOutCubic但前端更陡峭。 Here are several examples... 这里有几个例子...


(10)- easeOutQuart (10) easeOutQuart 缓释 easeOutQuart Demo easeOutQuart示范


(13)- easeOutQuint (13) easeOutQuint 逸出 easeOutQuint Demo easeOutQuint示范


(16)- easeOutExpo (16) easeOutExpo 展览会 easeOutExpo Demo easeOutExpo演示


It seems like the last one, easeOutExpo is the steepest stock function available. 好像最后一个一样, easeOutExpo是可用的最陡峭的股票函数。 By comparing the differences in the equations contained above, we can also manipulate the easeOutExpo equation to steepen the curve even further. 通过比较上面包含的方程式的差异,我们还可以操纵easeOutExpo方程式以进一步加深曲线。

This custom equation is ridiculously fast and then slows down tremendously... 这个自定义方程式快得离谱,然后大大放慢了速度。

http://jsfiddle.net/kJZxQ/11/ http://jsfiddle.net/kJZxQ/11/

Even more extreme than the last... 比上一个更加极端...

http://jsfiddle.net/kJZxQ/12/ http://jsfiddle.net/kJZxQ/12/

Duration increased on last demo to 6 seconds to exaggerate the effect... 上次演示的持续时间增加到6秒,以夸大效果。

http://jsfiddle.net/kJZxQ/13/ http://jsfiddle.net/kJZxQ/13/

By comparing the mathematical equations of the above demonstrations, you can see which variable is being manipulated to enhance the effect and make your own fine adjustments accordingly. 通过比较以上演示的数学方程式,您可以看到正在操纵哪个变量以增强效果并相应地进行自己的微调。

I really think easeOutExpo is more like what you describe. 我真的认为easeOutExpo更像您所描述的。 Essentially, it's your easeOutCubic equation but only faster on the front and slower on the end. 本质上,这是您的easeOutCubic公式,但仅在前面更快,在结尾更慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM