Bug Tracker

Ticket #928: jquery.easing.diff

File jquery.easing.diff, 1.7 KB (added by [email protected], 15 years ago)

Patch to cleanup the easing stuff

  • src/fx/fx.js

     
    301301         * @example $("p").animate({
    302302         *   opacity: 'show'
    303303         * }, "slow", "easein");
    304          * @desc An example of using an 'easing' function to provide a different style of animation. This will only work if you have a plugin that provides this easing function (Only 'linear' is provided by default, with jQuery).
     304         * @desc An example of using an 'easing' function to provide a different style of animation. This will only work if you have a plugin that provides this easing function (Only 'swing' and 'linear' are provided by default, with jQuery).
    305305         *
    306306         * @name animate
    307307         * @type jQuery
     
    379379                return opt;
    380380        },
    381381       
    382         easing: {},
     382        easing: {
     383                linear: function(percentage_elapsed, time_elapsed, value_start, value_difference, time_duration) {
     384                        return value_start + value_difference * percentage_elapsed;
     385                }
     386                swing: function(percentage_elapsed, time_elapsed, value_start, value_difference, time_duration) {
     387                        return value_start + value_difference * ((- Math.cos(percentage_elapsed * Math.PI) / 2) + 0.5);
     388                }
     389        },
    383390       
    384391        queue: {},
    385392       
     
    558565                                // If the easing function exists, then use it
    559566                                z.now = options.easing && jQuery.easing[options.easing] ?
    560567                                        jQuery.easing[options.easing](p, n,  firstNum, (lastNum-firstNum), options.duration) :
    561                                         // else use default linear easing
    562                                         ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
     568                                        jQuery.easing["swing"](p, n,  firstNum, (lastNum-firstNum), options.duration);
    563569
    564570                                // Perform the next step of the animation
    565571                                z.a();