Created
December 10, 2012 20:33
-
-
Save kmck/4253172 to your computer and use it in GitHub Desktop.
Blend an easing function with a linear function in jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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