web/rsln-opendata/res/metadataplayer/test/interface 1.2/source/easing.js
changeset 120 3daa4039509a
parent 119 4c86151704e9
child 121 2b794b7901d6
equal deleted inserted replaced
119:4c86151704e9 120:3daa4039509a
     1 /**
       
     2  * Interface Elements for jQuery
       
     3  * Easing formulas
       
     4  *
       
     5  * http://interface.eyecon.ro
       
     6  *
       
     7  * Copyright (c) 2006 Stefan Petre
       
     8  * Dual licensed under the MIT (MIT-LICENSE.txt)
       
     9  * and GPL (GPL-LICENSE.txt) licenses.
       
    10  */
       
    11  
       
    12 /**
       
    13  * Starting with jQuery 1.1  the fx function accepts easing formulas that can be used with .animation() and most of FX plugins from Interface. The object can be extended to accept new easing formulas
       
    14  */
       
    15  
       
    16  jQuery.extend({	
       
    17 	/**
       
    18 	 *
       
    19 	 * @param Integer p period step in animation
       
    20 	 * @param Integer n current time
       
    21 	 * @param Mixed firstNum begin value
       
    22 	 * @param Mixed delta change in
       
    23 	 * @param Integer duration duration
       
    24 	 */
       
    25 	easing :  {
       
    26 		linear: function(p, n, firstNum, delta, duration) {
       
    27 			return ((-Math.cos(p*Math.PI)/2) + 0.5) * delta + firstNum;
       
    28 		},
       
    29 		
       
    30 		easein: function(p, n, firstNum, delta, duration) {
       
    31 			return delta*(n/=duration)*n*n + firstNum;
       
    32 		},
       
    33 		
       
    34 		easeout: function(p, n, firstNum, delta, duration) {
       
    35 			return -delta * ((n=n/duration-1)*n*n*n - 1) + firstNum;
       
    36 		},
       
    37 		
       
    38 		easeboth: function(p, n, firstNum, delta, duration) {
       
    39 			if ((n/=duration/2) < 1)
       
    40 				return delta/2*n*n*n*n + firstNum;
       
    41 				return -delta/2 * ((n-=2)*n*n*n - 2) + firstNum;
       
    42 		},
       
    43 		
       
    44 		bounceout: function(p, n, firstNum, delta, duration) {
       
    45 			if ((n/=duration) < (1/2.75)) {
       
    46 				return delta*(7.5625*n*n) + firstNum;
       
    47 			} else if (n < (2/2.75)) {
       
    48 				return delta*(7.5625*(n-=(1.5/2.75))*n + .75) + firstNum;
       
    49 			} else if (n < (2.5/2.75)) {
       
    50 				return delta*(7.5625*(n-=(2.25/2.75))*n + .9375) + firstNum;
       
    51 			} else {
       
    52 				return delta*(7.5625*(n-=(2.625/2.75))*n + .984375) + firstNum;
       
    53 			}
       
    54 		},
       
    55 		
       
    56 		bouncein: function(p, n, firstNum, delta, duration) {
       
    57 			if (jQuery.easing.bounceout)
       
    58 				return delta - jQuery.easing.bounceout (p, duration - n, 0, delta, duration) + firstNum;
       
    59 			return firstNum + delta;
       
    60 		},
       
    61 		
       
    62 		bounceboth: function(p, n, firstNum, delta, duration) {
       
    63 			if (jQuery.easing.bouncein && jQuery.easing.bounceout)
       
    64 				if (n < duration/2)
       
    65 					return jQuery.easing.bouncein(p, n*2, 0, delta, duration) * .5 + firstNum;
       
    66 				return jQuery.easing.bounceout(p, n*2-duration, 0, delta, duration) * .5 + delta*.5 + firstNum; 
       
    67 			return firstNum + delta;
       
    68 		},
       
    69 		
       
    70 		elasticin: function(p, n, firstNum, delta, duration) {
       
    71 			var a, s;
       
    72    			if (n == 0)
       
    73    				return firstNum;
       
    74    			if ((n/=duration)==1)
       
    75    				return firstNum+delta;
       
    76    			a = delta * 0.3;
       
    77    			p=duration*.3;
       
    78 			if (a < Math.abs(delta)) {
       
    79 				a=delta;
       
    80 				s=p/4;
       
    81 			} else { 
       
    82 				s = p/(2*Math.PI) * Math.asin (delta/a);
       
    83 			}
       
    84 			return -(a*Math.pow(2,10*(n-=1)) * Math.sin( (n*duration-s)*(2*Math.PI)/p )) + firstNum; 
       
    85 		},
       
    86 		
       
    87 		elasticout:function(p, n, firstNum, delta, duration) {
       
    88 			var a, s;
       
    89 			if (n==0)
       
    90 				return firstNum;
       
    91 			if ((n/=duration/2)==2)
       
    92 				return firstNum + delta;
       
    93    			a = delta * 0.3;
       
    94    			p=duration*.3;
       
    95 			if (a < Math.abs(delta)){
       
    96 				a = delta;
       
    97 				s=p/4;
       
    98 			} else { 
       
    99 				s = p/(2*Math.PI) * Math.asin (delta/a);
       
   100 			}
       
   101 			return a*Math.pow(2,-10*n) * Math.sin( (n*duration-s)*(2*Math.PI)/p ) + delta + firstNum;
       
   102 		},
       
   103 		
       
   104 		elasticboth: function(p, n, firstNum, delta, duration) {
       
   105 			var a, s;
       
   106 			if (n==0)
       
   107 				return firstNum;
       
   108 			if ((n/=duration/2)==2)
       
   109 				return firstNum + delta;
       
   110    			a = delta * 0.3;
       
   111    			p=duration*.3;
       
   112 			if (a < Math.abs(delta)){
       
   113 				a = delta;
       
   114 				s=p/4;
       
   115 			} else { 
       
   116 				s = p/(2*Math.PI) * Math.asin (delta/a);
       
   117 			}
       
   118 			if (n < 1) {
       
   119 				return -.5*(a*Math.pow(2,10*(n-=1)) * Math.sin( (n*duration-s)*(2*Math.PI)/p )) + firstNum;
       
   120 			}
       
   121 			return a*Math.pow(2,-10*(n-=1)) * Math.sin( (n*duration-s)*(2*Math.PI)/p )*.5 + delta + firstNum; 
       
   122 		}
       
   123 	}
       
   124 });