includes/clientside/static/flyin.js
changeset 39 c83ff194977a
parent 1 fe660c52c48f
child 74 68469a95658d
equal deleted inserted replaced
38:ed06961e54dd 39:c83ff194977a
     8 var FI_BOTTOM = 2;
     8 var FI_BOTTOM = 2;
     9 var FI_IN = 1;
     9 var FI_IN = 1;
    10 var FI_OUT = 2;
    10 var FI_OUT = 2;
    11 var FI_UP = 1;
    11 var FI_UP = 1;
    12 var FI_DOWN = 2;
    12 var FI_DOWN = 2;
       
    13 
       
    14 /**
       
    15  * You can thank Robert Penner for the math used here. Ported from an ActionScript class.
       
    16  * License: Modified BSD license <http://www.robertpenner.com/easing_terms_of_use.html>
       
    17  */
       
    18 
       
    19 // Effects code - don't bother changing these formulas
       
    20 var Back = {
       
    21   easeOut: function(t, b, c, d, s)
       
    22   {
       
    23     if (s == undefined) s = 1.70158;
       
    24     return c * ( ( t=t/d-1 ) * t * ( ( s + 1 ) * t + s) + 1) + b;
       
    25   },
       
    26   easeIn: function (t, b, c, d, s)
       
    27   {
       
    28     if (s == undefined) s = 1.70158;
       
    29     return c * ( t/=d ) * t * ( ( s + 1 ) * t - s) + b;
       
    30   },
       
    31   easeInOut: function (t, b, c, d, s)
       
    32   {
       
    33     if (s == undefined) s = 1.70158; 
       
    34     if ((t /= d/2) < 1) 
       
    35     {
       
    36       return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
       
    37     }
       
    38     return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
       
    39   }
       
    40 }
       
    41 
       
    42 // This should be set to the class name of the effect you want.
       
    43 var GlideEffect = Back;
    13 
    44 
    14 // Placeholder functions, to make organization a little easier :-)
    45 // Placeholder functions, to make organization a little easier :-)
    15 
    46 
    16 function fly_in_top(element, nofade, height_taken_care_of)
    47 function fly_in_top(element, nofade, height_taken_care_of)
    17 {
    48 {
    89     top = h + y;
   120     top = h + y;
    90   }
   121   }
    91   
   122   
    92   var abs_dir = ( ( origin == FI_TOP && direction == FI_IN ) || ( origin == FI_BOTTOM && direction == FI_OUT ) ) ? FI_DOWN : FI_UP;
   123   var abs_dir = ( ( origin == FI_TOP && direction == FI_IN ) || ( origin == FI_BOTTOM && direction == FI_OUT ) ) ? FI_DOWN : FI_UP;
    93   
   124   
       
   125   var diff_top = top - topi;
       
   126   var diff_left = left - lefti;
       
   127   
       
   128   var frames = 100;
       
   129   var timeout = 0;
       
   130   var timerstep = 8;
       
   131   
       
   132   // cache element so it can be changed from within setTimeout()
       
   133   var rand_seed = Math.floor(Math.random() * 1000000);
       
   134   fly_in_cache[rand_seed] = element;
       
   135   
       
   136   for ( var i = 0; i < frames; i++ )
       
   137   {
       
   138     topc = GlideEffect.easeInOut(i, topi, diff_top, frames);
       
   139     leftc = GlideEffect.easeInOut(i, lefti, diff_left, frames);
       
   140     setTimeout('var o = fly_in_cache['+rand_seed+']; o.style.top=\''+topc+'px\'; o.style.left=\''+leftc+'px\';', timeout);
       
   141     timeout += timerstep;
       
   142     
       
   143     var ratio = i / frames;
       
   144     
       
   145     if ( !nofade )
       
   146     {
       
   147       // handle fade
       
   148       var opac_factor = ratio * 100;
       
   149       if ( direction == FI_OUT )
       
   150         opac_factor = 100 - opac_factor;
       
   151       setTimeout('var o = fly_in_cache['+rand_seed+']; domObjChangeOpac('+opac_factor+', o);', timeout);
       
   152     }
       
   153     
       
   154   }
       
   155   
    94   /*
   156   /*
    95    * Framestepper parameters
   157    * Framestepper parameters
    96    */
   158    * /
    97   
   159   
    98   // starting value for inertia
   160   // starting value for inertia
    99   var inertiabase = 1;
   161   var inertiabase = 1;
   100   // increment for inertia, or 0 to disable inertia effects
   162   // increment for inertia, or 0 to disable inertia effects
   101   var inertiainc  = 1;
   163   var inertiainc  = 1;
   104   // multiplier for deceleration, setting this above 2 can cause some weird slowdown effects
   166   // multiplier for deceleration, setting this above 2 can cause some weird slowdown effects
   105   var decelerate  = 2; // 1 / divider; // reciprocal of the divider
   167   var decelerate  = 2; // 1 / divider; // reciprocal of the divider
   106   
   168   
   107   /*
   169   /*
   108    * Timer parameters
   170    * Timer parameters
   109    */
   171    * /
   110   
   172   
   111   // how long animation start is delayed, you want this at 0
   173   // how long animation start is delayed, you want this at 0
   112   var timer = 0;
   174   var timer = 0;
   113   // frame ttl
   175   // frame ttl
   114   var timestep = 12;
   176   var timestep = 12;
   119   var rand_seed = Math.floor(Math.random() * 1000000);
   181   var rand_seed = Math.floor(Math.random() * 1000000);
   120   fly_in_cache[rand_seed] = element;
   182   fly_in_cache[rand_seed] = element;
   121   
   183   
   122   // set element left pos, you can comment this out to preserve left position
   184   // set element left pos, you can comment this out to preserve left position
   123   element.style.left = left + 'px';
   185   element.style.left = left + 'px';
   124   element.style.top  = topi + 'px';
       
   125   
       
   126   if ( nofade )
       
   127   {
       
   128     domObjChangeOpac(100, element);
       
   129   }
       
   130   
   186   
   131   // total distance to be traveled
   187   // total distance to be traveled
   132   dist = abs(top - topi);
   188   dist = abs(top - topi);
   133   
   189   
   134   // animation loop
   190   // animation loop
   179     // if we're done or if our sanity check failed then break out of the loop
   235     // if we're done or if our sanity check failed then break out of the loop
   180     if ( ( abs_dir == FI_DOWN && topi >= top ) || ( abs_dir == FI_UP && top >= topi ) || frames > 1000 )
   236     if ( ( abs_dir == FI_DOWN && topi >= top ) || ( abs_dir == FI_UP && top >= topi ) || frames > 1000 )
   181       break;
   237       break;
   182   }
   238   }
   183   
   239   
   184   //timer += timestep;
   240   timer += timestep;
   185   setTimeout('delete(fly_in_cache['+rand_seed+']);', timer);
   241   setTimeout('delete(fly_in_cache['+rand_seed+']);', timer);
   186   return timer;
   242   return timer;
       
   243   */
       
   244   timeout += timerstep;
       
   245   return timeout;
   187 }
   246 }
   188 
   247 
   189 function abs(i)
   248 function abs(i)
   190 {
   249 {
   191   if ( isNaN(i) )
   250   if ( isNaN(i) )