effects.clip.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * jQuery UI Effects Clip 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/Clip
  9. *
  10. * Depends:
  11. * effects.core.js
  12. */
  13. (function($) {
  14. $.effects.clip = function(o) {
  15. return this.queue(function() {
  16. // Create element
  17. var el = $(this), props = ['position','top','left','height','width'];
  18. // Set options
  19. var mode = $.effects.setMode(el, o.options.mode || 'hide'); // Set Mode
  20. var direction = o.options.direction || 'vertical'; // Default direction
  21. // Adjust
  22. $.effects.save(el, props); el.show(); // Save & Show
  23. var wrapper = $.effects.createWrapper(el).css({overflow:'hidden'}); // Create Wrapper
  24. var animate = el[0].tagName == 'IMG' ? wrapper : el;
  25. var ref = {
  26. size: (direction == 'vertical') ? 'height' : 'width',
  27. position: (direction == 'vertical') ? 'top' : 'left'
  28. };
  29. var distance = (direction == 'vertical') ? animate.height() : animate.width();
  30. if(mode == 'show') { animate.css(ref.size, 0); animate.css(ref.position, distance / 2); } // Shift
  31. // Animation
  32. var animation = {};
  33. animation[ref.size] = mode == 'show' ? distance : 0;
  34. animation[ref.position] = mode == 'show' ? 0 : distance / 2;
  35. // Animate
  36. animate.animate(animation, { queue: false, duration: o.duration, easing: o.options.easing, complete: function() {
  37. if(mode == 'hide') el.hide(); // Hide
  38. $.effects.restore(el, props); $.effects.removeWrapper(el); // Restore
  39. if(o.callback) o.callback.apply(el[0], arguments); // Callback
  40. el.dequeue();
  41. }});
  42. });
  43. };
  44. })(jQuery);