jquery.ui.effect-drop.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*!
  2. * jQuery UI Effects Drop v1.9 stable
  3. * http://jqueryui.com
  4. *
  5. * Copyright 2012 jQuery Foundation and other contributors
  6. * Released under the MIT license.
  7. * http://jquery.org/license
  8. *
  9. * http://api.jqueryui.com/drop-effect/
  10. *
  11. * Depends:
  12. * jquery.ui.effect.js
  13. */
  14. (function( $, undefined ) {
  15. $.effects.effect.drop = function( o, done ) {
  16. var el = $( this ),
  17. props = [ "position", "top", "bottom", "left", "right", "opacity", "height", "width" ],
  18. mode = $.effects.setMode( el, o.mode || "hide" ),
  19. show = mode === "show",
  20. direction = o.direction || "left",
  21. ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
  22. motion = ( direction === "up" || direction === "left" ) ? "pos" : "neg",
  23. animation = {
  24. opacity: show ? 1 : 0
  25. },
  26. distance;
  27. // Adjust
  28. $.effects.save( el, props );
  29. el.show();
  30. $.effects.createWrapper( el );
  31. distance = o.distance || el[ ref === "top" ? "outerHeight": "outerWidth" ]( true ) / 2;
  32. if ( show ) {
  33. el
  34. .css( "opacity", 0 )
  35. .css( ref, motion === "pos" ? -distance : distance );
  36. }
  37. // Animation
  38. animation[ ref ] = ( show ?
  39. ( motion === "pos" ? "+=" : "-=" ) :
  40. ( motion === "pos" ? "-=" : "+=" ) ) +
  41. distance;
  42. // Animate
  43. el.animate( animation, {
  44. queue: false,
  45. duration: o.duration,
  46. easing: o.easing,
  47. complete: function() {
  48. if ( mode === "hide" ) {
  49. el.hide();
  50. }
  51. $.effects.restore( el, props );
  52. $.effects.removeWrapper( el );
  53. done();
  54. }
  55. });
  56. };
  57. })(jQuery);