forked from shrekshrek/csstween
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsstween.min.js
More file actions
9 lines (8 loc) · 6.56 KB
/
csstween.min.js
File metadata and controls
9 lines (8 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
/*!
* VERSION: 0.6.0
* DATE: 2015-12-31
* GIT:https://github.com/shrekshrek/csstween
*
* @author: Shrek.wang, shrekshrek@gmail.com
**/
!function(t){var e="object"==typeof self&&self.self==self&&self||"object"==typeof global&&global.global==global&&global;"function"==typeof define&&define.amd?define(["exports"],function(n){e.CT=t(e,n)}):"undefined"!=typeof exports?t(e,exports):e.CT=t(e,{})}(function(t,e){function n(t,e){for(var n in e)t[n]=e[n]}function r(t,e){if("function"==typeof t)e.call(t,0,t);else if(void 0===t.length)e.call(t,0,t);else for(var n=0;n<t.length;n++)e.call(t[n],n,t[n])}function i(t){return t.replace(/([A-Z])/g,"-$1").toLowerCase()}function a(t){return t.replace(/\b(\w)|\s(\w)/g,function(t){return t.toUpperCase()})}function o(t){return t?E+a(t):E}function s(t){if(!t)throw"target is undefined, can't tween!!!";return"string"==typeof t?"undefined"==typeof document?t:document.querySelectorAll?document.querySelectorAll(t):document.getElementById("#"===t.charAt(0)?t.substr(1):t):t}function l(t,e){return void 0!==t.style[e]?e:(e=o(e),void 0!==t.style[e]?e:void 0)}function u(t,e){if("string"==typeof e){var n=e.substr(0,2),r=parseFloat(e.substr(2));switch(n){case"+=":e=parseFloat(t)+r;break;case"-=":e=parseFloat(t)-r}}return e}function d(t,e){switch(t){case"opacity":case"fontWeight":case"lineHeight":case"zoom":return e;default:return"number"==typeof e?Math.round(e)+"px":e}}function f(t,e){if(document.defaultView&&document.defaultView.getComputedStyle){var n=i(e),r=document.defaultView.getComputedStyle(t,"");return r&&r.getPropertyValue(n)}return t.currentStyle?t.currentStyle[e]:null}function h(t,e){for(var n in e)void 0!=t.style[n]&&(t.style[n]=d(n,e[n]))}function c(){return++F}function m(t){for(var e in b){var n=b[e];if(n.type===M&&n.name===t||n.type===T&&n.selectorText===t)return{rule:n,index:e}}return null}function v(t,e){var n=b.length;A.insertRule?A.insertRule(t+"{"+e+"}",n):A.addRule&&A.addRule(t,e,n)}function y(t){var e=m(t);null!==e&&(A.deleteRule?A.deleteRule(e.index):A.removeRule&&A.removeRule(e.index))}function p(t,e,n){var r="ct_kfs_"+t,a="0%{",s="100%{";for(var l in e)a+=i(l)+":"+d(l,e[l])+";",s+=i(l)+":"+d(l,n[l])+";";return a+="}",s+="}",v("@"+i(o("Keyframes"))+" "+r,a+s),r}function g(){return++V}function w(){this.initialize.apply(this,arguments)}var E="",R="animationstart",S="animationiteration",_="animationend",L="transitionend";!function(){var t=document.createElement("div"),e=["Webkit","Moz","Ms","O"];for(var n in e)if(e[n]+"Transition"in t.style){E=e[n],"Moz"!==E&&(R=E.toLowerCase()+"AnimationStart",S=E.toLowerCase()+"AnimationIteration",_=E.toLowerCase()+"AnimationEnd",L=E.toLowerCase()+"TransitionEnd");break}}();var A,b,C=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame,M=window.CSSRule.KEYFRAMES_RULE||window.CSSRule.WEBKIT_KEYFRAMES_RULE||window.CSSRule.MOZ_KEYFRAMES_RULE,T=window.CSSRule.STYLE_RULE||window.CSSRule.WEBKIT_STYLE_RULE||window.CSSRule.MOZ_STYLE_RULE,F=0;!function(){var t=document.createElement("style");t.rel="stylesheet",t.type="text/css",document.getElementsByTagName("head")[0].appendChild(t),A=t.sheet,b=A.cssRules||A.rules||[]}();var H={},V=0;return n(w.prototype,{initialize:function(t,n,r,i){var a=this;this.fromVars=r,this.toVars=i,this.target=t,this.duration=Math.max(n,0),this.ease="cubic-bezier"+(i.ease||e.Linear.None),this.delay=Math.max(i.delay||0,0),this.yoyo=i.yoyo||!1,this.repeat=Math.floor(i.repeat||1),this.onStart=i.onStart||null,this.onStartParams=i.onStartParams||[],this.onRepeat=i.onRepeat||null,this.onRepeatParams=i.onRepeatParams||[],this.onEnd=i.onEnd||null,this.onEndParams=i.onEndParams||[],this.type=i.type||"";var s=g();if(this.target._ct_id&&H[this.target._ct_id].destroy(),this.target._ct_id=s,"a"==this.type){this.startHandler=function(){a.onStart&&a.onStart.apply(this,a.onStartParams)},this.target.addEventListener(R,this.startHandler,!1),this.repeatHandler=function(){a.onRepeat&&a.onRepeat.apply(this,a.onRepeatParams)},this.target.addEventListener(S,this.repeatHandler,!1),this.endHandler=function(){a.destroy(!0)},this.target.addEventListener(_,this.endHandler,!1);var l=c();this.kfsName=p(l,this.fromVars,this.toVars),this.target.style[o("Animation")]=this.kfsName+" "+this.duration+"s "+this.ease+" "+this.delay+"s "+(this.repeat<0?"infinite":this.repeat)+" "+(this.yoyo?"alternate":"normal"),this.target.style[o("AnimationFillMode")]="both",h(this.target,this.toVars)}else this.endHandler=function(){a.destroy(!0)},this.target.addEventListener(L,this.endHandler,!1),C(function(){C(function(){a.target.style[o("Transition")]="all "+a.duration+"s "+a.ease+" "+a.delay+"s",h(a.target,a.toVars),console.log(a.target,a.toVars)})});H[s]=this},destroy:function(t){if(0==t)for(var e in this.toVars)void 0!=this.target.style[e]&&(this.target.style[e]=f(this.target,e));"a"==this.type?(this.target.removeEventListener(R,this.startHandler,!1),this.target.removeEventListener(S,this.repeatHandler,!1),this.target.removeEventListener(_,this.endHandler,!1),this.target.style[o("Animation")]="",this.target.style[o("AnimationFillMode")]="",y(this.kfsName)):(this.target.removeEventListener(L,this.endHandler,!1),this.target.style[o("Transition")]=""),delete H[this.target._ct_id],delete this.target._ct_id,1==t&&this.onEnd&&this.onEnd.apply(this,this.onEndParams)}}),n(e,{get:function(t,e){var n=s(t);void 0!==n.length&&(n=n[0]);var r=l(n,e);return r?f(n,r):null},set:function(t,e){var n=s(t);r(n,function(t,n){var r={};for(var i in e){var a=l(n,i);a&&(r[a]=d(a,u(f(n,a),e[i])))}h(n,r)})},fromTo:function(t,e,n,i){var a=s(t),o=[];return r(a,function(t,r){var a={},s={};for(var d in i){var c=l(r,d);if(c){var m=f(r,c);a[c]=u(m,n[d]),s[c]=u(m,i[d])}else s[d]=i[d]}h(r,a);var v=new w(r,e,a,s);o.push(v)}),1==o.length?o[0]:o},from:function(t,e,n){var i=s(t),a=[];return r(i,function(t,r){var i={},o={};for(var s in n){var d=l(r,s);if(d){var c=f(r,d);o[d]=c,i[d]=u(c,n[s])}else o[s]=n[s]}h(r,i);var m=new w(r,e,i,o);a.push(m)}),1==a.length?a[0]:a},to:function(t,e,n){var i=s(t),a=[];return r(i,function(t,r){var i={},o={};for(var s in n){var d=l(r,s);if(d){var h=f(r,d);i[d]=h,o[d]=u(h,n[s])}else o[s]=n[s]}var c=new w(r,e,i,o);a.push(c)}),1==a.length?a[0]:a},kill:function(t,e){var n=s(t);r(n,function(t,n){n._ct_id&&H[n._ct_id].destroy(e)})},killAll:function(t){for(var e in H)H[e].destroy(t)}}),n(e,{Linear:{None:"(0, 0, 1, 1)"},Quad:{In:"(0.3, 0, 0.65, 0.75)",Out:"(0.35, 0.25, 0.7, 1)",InOut:"(0.46, 0.03, 0.54, 0.97)"},Quart:{In:"(0.5, 0, 0.75, 0)",Out:"(0.25, 1, 0.5, 1)",InOut:"(0.75, 0, 0.25, 1)"},Back:{In:"(0, 0.35, 0.7, -0.6)",Out:"(0.3, 1.6, 0.65, 1)"}}),e});