jquery.effects.slide.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * jQuery UI Effects Slide 1.8.11
  3. *
  4. * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
  5. * Dual licensed under the MIT or GPL Version 2 licenses.
  6. * http://jquery.org/license
  7. *
  8. * http://docs.jquery.com/UI/Effects/Slide
  9. *
  10. * Depends:
  11. * jquery.effects.core.js
  12. */
  13. (function( $, undefined ) {
  14. $.effects.slide = function(o) {
  15. return this.queue(function() {
  16. // Create element
  17. var el = $(this), props = ['position','top','bottom','left','right'];
  18. // Set options
  19. var mode = $.effects.setMode(el, o.options.mode || 'show'); // Set Mode
  20. var direction = o.options.direction || 'left'; // Default Direction
  21. // Adjust
  22. $.effects.save(el, props); el.show(); // Save & Show
  23. $.effects.createWrapper(el).css({overflow:'hidden'}); // Create Wrapper
  24. var ref = (direction == 'up' || direction == 'down') ? 'top' : 'left';
  25. var motion = (direction == 'up' || direction == 'left') ? 'pos' : 'neg';
  26. var distance = o.options.distance || (ref == 'top' ? el.outerHeight({margin:true}) : el.outerWidth({margin:true}));
  27. if (mode == 'show') el.css(ref, motion == 'pos' ? (isNaN(distance) ? "-" + distance : -distance) : distance); // Shift
  28. // Animation
  29. var animation = {};
  30. animation[ref] = (mode == 'show' ? (motion == 'pos' ? '+=' : '-=') : (motion == 'pos' ? '-=' : '+=')) + distance;
  31. // Animate
  32. el.animate(animation, { queue: false, duration: o.duration, easing: o.options.easing, complete: function() {
  33. if(mode == 'hide') el.hide(); // Hide
  34. $.effects.restore(el, props); $.effects.removeWrapper(el); // Restore
  35. if(o.callback) o.callback.apply(this, arguments); // Callback
  36. el.dequeue();
  37. }});
  38. });
  39. };
  40. })(jQuery);