暫無描述

effect-drop.js 1.5KB

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