1
0

effect-explode.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*!
  2. * jQuery UI Effects Explode 1.11.4
  3. * http://jqueryui.com
  4. *
  5. * Copyright jQuery Foundation and other contributors
  6. * Released under the MIT license.
  7. * http://jquery.org/license
  8. *
  9. * http://api.jqueryui.com/explode-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.explode = function( o, done ) {
  24. var rows = o.pieces ? Math.round( Math.sqrt( o.pieces ) ) : 3,
  25. cells = rows,
  26. el = $( this ),
  27. mode = $.effects.setMode( el, o.mode || "hide" ),
  28. show = mode === "show",
  29. // show and then visibility:hidden the element before calculating offset
  30. offset = el.show().css( "visibility", "hidden" ).offset(),
  31. // width and height of a piece
  32. width = Math.ceil( el.outerWidth() / cells ),
  33. height = Math.ceil( el.outerHeight() / rows ),
  34. pieces = [],
  35. // loop
  36. i, j, left, top, mx, my;
  37. // children animate complete:
  38. function childComplete() {
  39. pieces.push( this );
  40. if ( pieces.length === rows * cells ) {
  41. animComplete();
  42. }
  43. }
  44. // clone the element for each row and cell.
  45. for ( i = 0; i < rows ; i++ ) { // ===>
  46. top = offset.top + i * height;
  47. my = i - ( rows - 1 ) / 2 ;
  48. for ( j = 0; j < cells ; j++ ) { // |||
  49. left = offset.left + j * width;
  50. mx = j - ( cells - 1 ) / 2 ;
  51. // Create a clone of the now hidden main element that will be absolute positioned
  52. // within a wrapper div off the -left and -top equal to size of our pieces
  53. el
  54. .clone()
  55. .appendTo( "body" )
  56. .wrap( "<div></div>" )
  57. .css({
  58. position: "absolute",
  59. visibility: "visible",
  60. left: -j * width,
  61. top: -i * height
  62. })
  63. // select the wrapper - make it overflow: hidden and absolute positioned based on
  64. // where the original was located +left and +top equal to the size of pieces
  65. .parent()
  66. .addClass( "ui-effects-explode" )
  67. .css({
  68. position: "absolute",
  69. overflow: "hidden",
  70. width: width,
  71. height: height,
  72. left: left + ( show ? mx * width : 0 ),
  73. top: top + ( show ? my * height : 0 ),
  74. opacity: show ? 0 : 1
  75. }).animate({
  76. left: left + ( show ? 0 : mx * width ),
  77. top: top + ( show ? 0 : my * height ),
  78. opacity: show ? 1 : 0
  79. }, o.duration || 500, o.easing, childComplete );
  80. }
  81. }
  82. function animComplete() {
  83. el.css({
  84. visibility: "visible"
  85. });
  86. $( pieces ).remove();
  87. if ( !show ) {
  88. el.hide();
  89. }
  90. done();
  91. }
  92. };
  93. }));