You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.8 KiB

1 year ago
  1. /*!
  2. * jQuery UI Effects Explode 1.13.2
  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. //>>label: Explode Effect
  10. //>>group: Effects
  11. /* eslint-disable max-len */
  12. //>>description: Explodes an element in all directions into n pieces. Implodes an element to its original wholeness.
  13. /* eslint-enable max-len */
  14. //>>docs: http://api.jqueryui.com/explode-effect/
  15. //>>demos: http://jqueryui.com/effect/
  16. ( function( factory ) {
  17. "use strict";
  18. if ( typeof define === "function" && define.amd ) {
  19. // AMD. Register as an anonymous module.
  20. define( [
  21. "jquery",
  22. "./effect"
  23. ], factory );
  24. } else {
  25. // Browser globals
  26. factory( jQuery );
  27. }
  28. } )( function( $ ) {
  29. "use strict";
  30. return $.effects.define( "explode", "hide", function( options, done ) {
  31. var i, j, left, top, mx, my,
  32. rows = options.pieces ? Math.round( Math.sqrt( options.pieces ) ) : 3,
  33. cells = rows,
  34. element = $( this ),
  35. mode = options.mode,
  36. show = mode === "show",
  37. // Show and then visibility:hidden the element before calculating offset
  38. offset = element.show().css( "visibility", "hidden" ).offset(),
  39. // Width and height of a piece
  40. width = Math.ceil( element.outerWidth() / cells ),
  41. height = Math.ceil( element.outerHeight() / rows ),
  42. pieces = [];
  43. // Children animate complete:
  44. function childComplete() {
  45. pieces.push( this );
  46. if ( pieces.length === rows * cells ) {
  47. animComplete();
  48. }
  49. }
  50. // Clone the element for each row and cell.
  51. for ( i = 0; i < rows; i++ ) { // ===>
  52. top = offset.top + i * height;
  53. my = i - ( rows - 1 ) / 2;
  54. for ( j = 0; j < cells; j++ ) { // |||
  55. left = offset.left + j * width;
  56. mx = j - ( cells - 1 ) / 2;
  57. // Create a clone of the now hidden main element that will be absolute positioned
  58. // within a wrapper div off the -left and -top equal to size of our pieces
  59. element
  60. .clone()
  61. .appendTo( "body" )
  62. .wrap( "<div></div>" )
  63. .css( {
  64. position: "absolute",
  65. visibility: "visible",
  66. left: -j * width,
  67. top: -i * height
  68. } )
  69. // Select the wrapper - make it overflow: hidden and absolute positioned based on
  70. // where the original was located +left and +top equal to the size of pieces
  71. .parent()
  72. .addClass( "ui-effects-explode" )
  73. .css( {
  74. position: "absolute",
  75. overflow: "hidden",
  76. width: width,
  77. height: height,
  78. left: left + ( show ? mx * width : 0 ),
  79. top: top + ( show ? my * height : 0 ),
  80. opacity: show ? 0 : 1
  81. } )
  82. .animate( {
  83. left: left + ( show ? 0 : mx * width ),
  84. top: top + ( show ? 0 : my * height ),
  85. opacity: show ? 1 : 0
  86. }, options.duration || 500, options.easing, childComplete );
  87. }
  88. }
  89. function animComplete() {
  90. element.css( {
  91. visibility: "visible"
  92. } );
  93. $( pieces ).remove();
  94. done();
  95. }
  96. } );
  97. } );