|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
( function( factory ) { |
|
"use strict"; |
|
|
|
if ( typeof define === "function" && define.amd ) { |
|
|
|
|
|
define( [ |
|
"jquery", |
|
"../version", |
|
"../effect" |
|
], factory ); |
|
} else { |
|
|
|
|
|
factory( jQuery ); |
|
} |
|
} )( function( $ ) { |
|
"use strict"; |
|
|
|
return $.effects.define( "explode", "hide", function( options, done ) { |
|
|
|
var i, j, left, top, mx, my, |
|
rows = options.pieces ? Math.round( Math.sqrt( options.pieces ) ) : 3, |
|
cells = rows, |
|
element = $( this ), |
|
mode = options.mode, |
|
show = mode === "show", |
|
|
|
|
|
offset = element.show().css( "visibility", "hidden" ).offset(), |
|
|
|
|
|
width = Math.ceil( element.outerWidth() / cells ), |
|
height = Math.ceil( element.outerHeight() / rows ), |
|
pieces = []; |
|
|
|
|
|
function childComplete() { |
|
pieces.push( this ); |
|
if ( pieces.length === rows * cells ) { |
|
animComplete(); |
|
} |
|
} |
|
|
|
|
|
for ( i = 0; i < rows; i++ ) { |
|
top = offset.top + i * height; |
|
my = i - ( rows - 1 ) / 2; |
|
|
|
for ( j = 0; j < cells; j++ ) { |
|
left = offset.left + j * width; |
|
mx = j - ( cells - 1 ) / 2; |
|
|
|
|
|
|
|
element |
|
.clone() |
|
.appendTo( "body" ) |
|
.wrap( "<div></div>" ) |
|
.css( { |
|
position: "absolute", |
|
visibility: "visible", |
|
left: -j * width, |
|
top: -i * height |
|
} ) |
|
|
|
|
|
|
|
.parent() |
|
.addClass( "ui-effects-explode" ) |
|
.css( { |
|
position: "absolute", |
|
overflow: "hidden", |
|
width: width, |
|
height: height, |
|
left: left + ( show ? mx * width : 0 ), |
|
top: top + ( show ? my * height : 0 ), |
|
opacity: show ? 0 : 1 |
|
} ) |
|
.animate( { |
|
left: left + ( show ? 0 : mx * width ), |
|
top: top + ( show ? 0 : my * height ), |
|
opacity: show ? 1 : 0 |
|
}, options.duration || 500, options.easing, childComplete ); |
|
} |
|
} |
|
|
|
function animComplete() { |
|
element.css( { |
|
visibility: "visible" |
|
} ); |
|
$( pieces ).remove(); |
|
done(); |
|
} |
|
} ); |
|
|
|
} ); |
|
|