How does the easing function for jQuery work? Take for example:
easeInQuad = function (x, t, b, c, d) { return c*(t/=d)*t + b; };
How does that work? What does each parameter hold? How would I implement some dumb easing for an animation?
Also how would I attach an easing pattern to jQuery, is loading it into $.easing good enough?
According to the jQuery 1.6.2 source, the meaning of the easing function is as follows. The function is called at various points in time during the animation. At the instants it is called,
As far as I can see, jQuery doesn't give you direct control over when the animation step function is called, it only lets you say "if I am called at time t, then I should be thus far through the entire animation." Therefore you cannot, for example, ask for your object to be redrawn more frequently at times when it is moving faster. Also, I don't know why other people say b is the start value and c is the change -- that's not what jQuery source code says.
If you wanted to define your own easing function to do the same as easeInQuad, for example,
$.extend(jQuery.easing,{myfunc:function(x,t,b,c,d) { return x*x; }}) $('#marker').animate({left:'800px'},'slow','myfunc');
$.extend(jQuery.easing,{myfunc:function(x,t,b,c,d) { return x*x; }}) $('#marker').animate({left:'500px'},'slow','myfunc');
#marker { position: absolute; left: 10px; top: 50px; background: red; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id='marker'>Hello World!</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With