effect-drop.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*!
  2. * jQuery UI Effects Drop 1.14.1
  3. * https://jqueryui.com
  4. *
  5. * Copyright OpenJS Foundation and other contributors
  6. * Released under the MIT license.
  7. * https://jquery.org/license
  8. */
  9. //>>label: Drop Effect
  10. //>>group: Effects
  11. //>>description: Moves an element in one direction and hides it at the same time.
  12. //>>docs: https://api.jqueryui.com/drop-effect/
  13. //>>demos: https://jqueryui.com/effect/
  14. ( function( factory ) {
  15. "use strict";
  16. if ( typeof define === "function" && define.amd ) {
  17. // AMD. Register as an anonymous module.
  18. define( [
  19. "jquery",
  20. "../version",
  21. "../effect"
  22. ], factory );
  23. } else {
  24. // Browser globals
  25. factory( jQuery );
  26. }
  27. } )( function( $ ) {
  28. "use strict";
  29. return $.effects.define( "drop", "hide", function( options, done ) {
  30. var distance,
  31. element = $( this ),
  32. mode = options.mode,
  33. show = mode === "show",
  34. direction = options.direction || "left",
  35. ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
  36. motion = ( direction === "up" || direction === "left" ) ? "-=" : "+=",
  37. oppositeMotion = ( motion === "+=" ) ? "-=" : "+=",
  38. animation = {
  39. opacity: 0
  40. };
  41. $.effects.createPlaceholder( element );
  42. distance = options.distance ||
  43. element[ ref === "top" ? "outerHeight" : "outerWidth" ]( true ) / 2;
  44. animation[ ref ] = motion + distance;
  45. if ( show ) {
  46. element.css( animation );
  47. animation[ ref ] = oppositeMotion + distance;
  48. animation.opacity = 1;
  49. }
  50. // Animate
  51. element.animate( animation, {
  52. queue: false,
  53. duration: options.duration,
  54. easing: options.easing,
  55. complete: done
  56. } );
  57. } );
  58. } );