effect-drop.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*!
  2. * jQuery UI Effects Drop 1.11.4
  3. * http://jqueryui.com
  4. *
  5. * Copyright 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. (function( factory ) {
  12. if ( typeof define === "function" && define.amd ) {
  13. // AMD. Register as an anonymous module.
  14. define([
  15. "jquery",
  16. "./effect"
  17. ], factory );
  18. } else {
  19. // Browser globals
  20. factory( jQuery );
  21. }
  22. }(function( $ ) {
  23. return $.effects.effect.drop = function( o, done ) {
  24. var el = $( this ),
  25. props = [ "position", "top", "bottom", "left", "right", "opacity", "height", "width" ],
  26. mode = $.effects.setMode( el, o.mode || "hide" ),
  27. show = mode === "show",
  28. direction = o.direction || "left",
  29. ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
  30. motion = ( direction === "up" || direction === "left" ) ? "pos" : "neg",
  31. animation = {
  32. opacity: show ? 1 : 0
  33. },
  34. distance;
  35. // Adjust
  36. $.effects.save( el, props );
  37. el.show();
  38. $.effects.createWrapper( el );
  39. distance = o.distance || el[ ref === "top" ? "outerHeight" : "outerWidth" ]( true ) / 2;
  40. if ( show ) {
  41. el
  42. .css( "opacity", 0 )
  43. .css( ref, motion === "pos" ? -distance : distance );
  44. }
  45. // Animation
  46. animation[ ref ] = ( show ?
  47. ( motion === "pos" ? "+=" : "-=" ) :
  48. ( motion === "pos" ? "-=" : "+=" ) ) +
  49. distance;
  50. // Animate
  51. el.animate( animation, {
  52. queue: false,
  53. duration: o.duration,
  54. easing: o.easing,
  55. complete: function() {
  56. if ( mode === "hide" ) {
  57. el.hide();
  58. }
  59. $.effects.restore( el, props );
  60. $.effects.removeWrapper( el );
  61. done();
  62. }
  63. });
  64. };
  65. }));