admin管理员组文章数量:1220818
I'm using the jQuery easing plugin by Robert (/) and I need to emphasizing or drag out the ease effect.
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.
How can this be achieved?
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.
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.
How can this be achieved?
Share Improve this question edited Oct 13, 2011 at 17:49 Sparky 98.7k26 gold badges202 silver badges290 bronze badges asked Oct 13, 2011 at 2:00 ParamountParamount 1,10714 silver badges27 bronze badges1 Answer
Reset to default 19You do not need an easing plugin to do custom easing with jQuery. You only need the source JavaScript code of the one easing function you are going to use.
Here is the easeOutCubic
function obtained from the jQuery UI source code. 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.)
Then you just put it inside your jQuery, something like this perhaps...
$(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.
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
:
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/
As you can see, several curves are shaped similarly to (7)-easeOutCubic
yet are steeper on the front end. Here are several examples...
(10)-easeOutQuart
easeOutQuart Demo
(13)-easeOutQuint
easeOutQuint Demo
(16)-easeOutExpo
easeOutExpo Demo
It seems like the last one, easeOutExpo
is the steepest stock function available. By comparing the differences in the equations contained above, we can also manipulate the easeOutExpo
equation to steepen the curve even further.
This custom equation is ridiculously fast and then slows down tremendously...
http://jsfiddle.net/kJZxQ/11/
Even more extreme than the last...
http://jsfiddle.net/kJZxQ/12/
Duration increased on last demo to 6 seconds to exaggerate the effect...
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. Essentially, it's your easeOutCubic
equation but only faster on the front and slower on the end.
本文标签: javascriptjQueryeasingeaseOutCubicemphasizing on the easeStack Overflow
版权声明:本文标题:javascript - jQuery.easing - easeOutCubic - emphasizing on the ease - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739351063a2159389.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论