Skip to content

Instantly share code, notes, and snippets.

@kmck
Created December 10, 2012 20:33
Show Gist options
  • Save kmck/4253172 to your computer and use it in GitHub Desktop.
Save kmck/4253172 to your computer and use it in GitHub Desktop.
Blend an easing function with a linear function in jQuery
(function($){
/**
* Creates a version of the specified easing function averaged with linear
* easing at the specified weight
*
* @param name of original easing function
* @param weight of easing function (default 0.5)
* @return name of rounded easing function
*/
$.linearBlendEase = function ( fn, weight )
{
weight = weight || 0.5;
var fnBlend = fn + 'Blend' + weight;
// If the function does not exist yet, create it first
if ( typeof $.easing[fnBlend] !== 'function' )
{
$.easing[fnBlend] = function (x, t, b, c, d) {
return weight * $.easing[fn](x, t, b, c, d ) + ( 1 - weight ) * ( c * t / d + b );
};
}
// And use it!
return fnBlend;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment