effects.explode.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * jQuery UI Effects Explode 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/Explode
  9. *
  10. * Depends:
  11. * effects.core.js
  12. */
  13. (function($) {
  14. $.effects.explode = function(o) {
  15. return this.queue(function() {
  16. var rows = o.options.pieces ? Math.round(Math.sqrt(o.options.pieces)) : 3;
  17. var cells = o.options.pieces ? Math.round(Math.sqrt(o.options.pieces)) : 3;
  18. o.options.mode = o.options.mode == 'toggle' ? ($(this).is(':visible') ? 'hide' : 'show') : o.options.mode;
  19. var el = $(this).show().css('visibility', 'hidden');
  20. var offset = el.offset();
  21. //Substract the margins - not fixing the problem yet.
  22. offset.top -= parseInt(el.css("marginTop"),10) || 0;
  23. offset.left -= parseInt(el.css("marginLeft"),10) || 0;
  24. var width = el.outerWidth(true);
  25. var height = el.outerHeight(true);
  26. for(var i=0;i<rows;i++) { // =
  27. for(var j=0;j<cells;j++) { // ||
  28. el
  29. .clone()
  30. .appendTo('body')
  31. .wrap('<div></div>')
  32. .css({
  33. position: 'absolute',
  34. visibility: 'visible',
  35. left: -j*(width/cells),
  36. top: -i*(height/rows)
  37. })
  38. .parent()
  39. .addClass('ui-effects-explode')
  40. .css({
  41. position: 'absolute',
  42. overflow: 'hidden',
  43. width: width/cells,
  44. height: height/rows,
  45. left: offset.left + j*(width/cells) + (o.options.mode == 'show' ? (j-Math.floor(cells/2))*(width/cells) : 0),
  46. top: offset.top + i*(height/rows) + (o.options.mode == 'show' ? (i-Math.floor(rows/2))*(height/rows) : 0),
  47. opacity: o.options.mode == 'show' ? 0 : 1
  48. }).animate({
  49. left: offset.left + j*(width/cells) + (o.options.mode == 'show' ? 0 : (j-Math.floor(cells/2))*(width/cells)),
  50. top: offset.top + i*(height/rows) + (o.options.mode == 'show' ? 0 : (i-Math.floor(rows/2))*(height/rows)),
  51. opacity: o.options.mode == 'show' ? 1 : 0
  52. }, o.duration || 500);
  53. }
  54. }
  55. // Set a timeout, to call the callback approx. when the other animations have finished
  56. setTimeout(function() {
  57. o.options.mode == 'show' ? el.css({ visibility: 'visible' }) : el.css({ visibility: 'visible' }).hide();
  58. if(o.callback) o.callback.apply(el[0]); // Callback
  59. el.dequeue();
  60. $('div.ui-effects-explode').remove();
  61. }, o.duration || 500);
  62. });
  63. };
  64. })(jQuery);