Created
June 29, 2016 02:17
-
-
Save vace/50ade7d03a985b5e7c606a19073d4281 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
var easings = (function() { | |
var eases = {}; | |
var names = ['Quad', 'Cubic', 'Quart', 'Quint', 'Expo']; | |
var functions = { | |
Sine: function(t) { return 1 - Math.cos( t * Math.PI / 2 ); }, | |
Circ: function(t) { return 1 - Math.sqrt( 1 - t * t ); }, | |
Elastic: function(t, m) { | |
if( t === 0 || t === 1 ) return t; | |
var p = (1 - Math.min(m, 998) / 1000), st = t / 1, st1 = st - 1, s = p / ( 2 * Math.PI ) * Math.asin( 1 ); | |
return -( Math.pow( 2, 10 * st1 ) * Math.sin( ( st1 - s ) * ( 2 * Math.PI ) / p ) ); | |
}, | |
Back: function(t) { return t * t * ( 3 * t - 2 ); }, | |
Bounce: function(t) { | |
var pow2, bounce = 4; | |
while ( t < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {} | |
return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - t, 2 ); | |
} | |
} | |
names.forEach(function(name, i) { | |
functions[name] = function(t) { | |
return Math.pow( t, i + 2 ); | |
} | |
}); | |
Object.keys(functions).forEach(function(name) { | |
var easeIn = functions[name]; | |
eases['easeIn' + name] = easeIn; | |
eases['easeOut' + name] = function(t, m) { return 1 - easeIn(1 - t, m); }; | |
eases['easeInOut' + name] = function(t, m) { return t < 0.5 ? easeIn(t * 2, m) / 2 : 1 - easeIn(t * -2 + 2, m) / 2; }; | |
}); | |
eases.linear = function(t) { return t; }; | |
return eases; | |
})(); |
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
var is = (function() { | |
return { | |
array: function(a) { return Array.isArray(a) }, | |
object: function(a) { return Object.prototype.toString.call(a).indexOf('Object') > -1 }, | |
html: function(a) { return (a instanceof NodeList || a instanceof HTMLCollection) }, | |
node: function(a) { return a.nodeType }, | |
svg: function(a) { return a instanceof SVGElement }, | |
number: function(a) { return !isNaN(parseInt(a)) }, | |
string: function(a) { return typeof a === 'string' }, | |
func: function(a) { return typeof a === 'function' }, | |
undef: function(a) { return typeof a === 'undefined' }, | |
null: function(a) { return typeof a === 'null' }, | |
hex: function(a) { return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a) }, | |
rgb: function(a) { return /^rgb/.test(a) }, | |
rgba: function(a) { return /^rgba/.test(a) }, | |
hsl: function(a) { return /^hsl/.test(a) }, | |
color: function(a) { return (is.hex(a) || is.rgb(a) || is.rgba(a) || is.hsl(a))} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment