Last active
August 19, 2016 11:14
-
-
Save hu9o/a7e765e628bdd4928e4709d26426a8b1 to your computer and use it in GitHub Desktop.
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
//////// | |
// CustomEase for GSAP (ES5) | |
//////// | |
// Written using code from greensock/GreenSock-JS : | |
// https://github.com/greensock/GreenSock-JS/blob/master/src/uncompressed/easing/EasePack.js | |
var _gsScope = (typeof(module) !== "undefined" && module.exports && typeof(global) !== "undefined") ? global : this || window; //helps ensure compatibility with AMD/RequireJS and CommonJS/Node | |
var gs = (_gsScope.GreenSockGlobals || _gsScope).com.greensock; | |
var CustomEase = gs._class("easing.CustomEase", function(func) { | |
this.getRatio = func; | |
}, true); | |
var p = CustomEase.prototype = new Ease(); | |
p.constructor = CustomEase; | |
p.config = CustomEase.config = function(steps) { | |
return new CustomEase(steps); | |
}; | |
if (Ease.register) | |
Ease.register(CustomEase, "CustomEase", "ease,"); | |
//////// | |
// Usage | |
//////// | |
// Easing functions examples : | |
function linearRatio(x) { | |
return x; | |
} | |
function quadraticEaseInRatio(x) { | |
return x * x; | |
} | |
function cosineRatio(x) { | |
return Math.cos(x * Math.PI)*-0.5 + 0.5); | |
} | |
// Get your Easing object : | |
var CosineEase = CustomEase.config(cosineRatio); | |
// Use it like your average GSAP Easing: | |
TweenLite.to($box, 2, { x: 100, ease: CosineEase }); | |
//// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment