1. /**
  2.  * Modded animate() for jQuery
  3.  * ---------------------------
  4.  * Allows you to specify additional easing functions on
  5.  * a per-property basis, E.g.
  6.  * $().animate({
  7.  * left: 200,
  8.  * top: [200, 'easeOutBounce']
  9.  * });
  10.  * ---------------------------
  11.  * @author James Padolsey
  12.  * @info
  13.  */
  14.  
  15. jQuery.fn.animate = (function(_anim){
  16.  
  17. var jQEasing = jQuery.easing;
  18.  
  19. return function(prop, duration, easing, callback) {
  20.  
  21. var props = {}, optall, i, hasEaser = false;
  22.  
  23. for ( i in prop ) {
  24. if ( jQuery.isArray(prop[i]) ) {
  25. hasEaser = true;
  26. props[i] = prop[i][1];
  27. prop[i] = prop[i][0];
  28. }
  29. }
  30.  
  31. opt = jQuery.speed(duration, easing, callback);
  32.  
  33. if (hasEaser) {
  34.  
  35. opt.step = (function(_step){
  36. return function(now, fx) {
  37. var end = fx.end, easeFn;
  38. if ( easeFn = props[fx.prop] ) {
  39. fx.now = jQEasing[easeFn]( now/end, now, 0, end, end );
  40. }
  41. _step && _step.call( fx.elem, fx.now, fx );
  42. };
  43. })(opt.step);
  44.  
  45. }
  46.  
  47. opt.complete = opt.old || callback || jQuery.isFunction(easing) && easing;
  48.  
  49. return _anim.call( this, prop, opt );
  50.  
  51. };
  52.  
  53. })(jQuery.fn.animate);

ALL COPYRIGHT © James Padolsey unless otherwise specified
Go back to the top