effects.slide.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * jQuery UI Effects Slide 1.7.2
  3. *
  4. * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
  5. * Dual licensed under the MIT (MIT-LICENSE.txt)
  6. * and GPL (GPL-LICENSE.txt) licenses.
  7. *
  8. * http://docs.jquery.com/UI/Effects/Slide
  9. *
  10. * Depends:
  11. * effects.core.js
  12. */
  13. (function($) {
  14. $.effects.slide = function(o) {
  15. return this.queue(function() {
  16. // Create element
  17. var el = $(this), props = ['position','top','left'];
  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' ? -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);