effect-slide.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*!
  2. * jQuery UI Effects Slide 1.11.2
  3. * http://jqueryui.com
  4. *
  5. * Copyright 2014 jQuery Foundation and other contributors
  6. * Released under the MIT license.
  7. * http://jquery.org/license
  8. *
  9. * http://api.jqueryui.com/slide-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.slide = function( o, done ) {
  24. // Create element
  25. var el = $( this ),
  26. props = [ "position", "top", "bottom", "left", "right", "width", "height" ],
  27. mode = $.effects.setMode( el, o.mode || "show" ),
  28. show = mode === "show",
  29. direction = o.direction || "left",
  30. ref = (direction === "up" || direction === "down") ? "top" : "left",
  31. positiveMotion = (direction === "up" || direction === "left"),
  32. distance,
  33. animation = {};
  34. // Adjust
  35. $.effects.save( el, props );
  36. el.show();
  37. distance = o.distance || el[ ref === "top" ? "outerHeight" : "outerWidth" ]( true );
  38. $.effects.createWrapper( el ).css({
  39. overflow: "hidden"
  40. });
  41. if ( show ) {
  42. el.css( ref, positiveMotion ? (isNaN(distance) ? "-" + distance : -distance) : distance );
  43. }
  44. // Animation
  45. animation[ ref ] = ( show ?
  46. ( positiveMotion ? "+=" : "-=") :
  47. ( positiveMotion ? "-=" : "+=")) +
  48. distance;
  49. // Animate
  50. el.animate( animation, {
  51. queue: false,
  52. duration: o.duration,
  53. easing: o.easing,
  54. complete: function() {
  55. if ( mode === "hide" ) {
  56. el.hide();
  57. }
  58. $.effects.restore( el, props );
  59. $.effects.removeWrapper( el );
  60. done();
  61. }
  62. });
  63. };
  64. }));