@@ -18,45 +18,62 @@ $.effects.explode = function( o ) {
18
18
19
19
var rows = o . pieces ? Math . round ( Math . sqrt ( o . pieces ) ) : 3 ,
20
20
cells = rows ,
21
- el = $ ( this ) . show ( ) . css ( 'visibility' , 'hidden' ) ,
21
+ el = $ ( this ) ,
22
22
mode = $ . effects . setMode ( el , o . mode || 'hide' ) ,
23
- offset = el . offset ( ) ,
24
- width = el . outerWidth ( true ) ,
25
- height = el . outerHeight ( true ) ,
26
- peices = [ ] ;
23
+ show = ( mode == 'show' ) ,
27
24
28
- //Substract the margins - not fixing the problem yet.
29
- offset . top -= parseInt ( el . css ( "marginTop" ) , 10 ) || 0 ;
30
- offset . left -= parseInt ( el . css ( "marginLeft" ) , 10 ) || 0 ;
25
+ // show and then visibility:hidden the element before calculating offset
26
+ offset = el . show ( ) . css ( 'visibility' , 'hidden' ) . offset ( ) ,
27
+
28
+ // width and height of a piece
29
+ width = Math . ceil ( el . outerWidth ( ) / cells ) ,
30
+ height = Math . ceil ( el . outerHeight ( ) / rows ) ,
31
+ peices = [ ] ,
32
+ i , j , pos ;
31
33
32
34
// clone the element for each row and cell.
33
- for ( var i = 0 ; i < rows ; i ++ ) { // =
34
- for ( var j = 0 ; j < cells ; j ++ ) { // ||
35
+ for ( i = 0 ; i < rows ; i ++ ) { // ===>
36
+ for ( j = 0 ; j < cells ; j ++ ) { // |||
37
+ pos = {
38
+ // wrapper base position in body
39
+ left : offset . left + j * width ,
40
+ top : offset . top + i * height ,
41
+
42
+ // x position in matrix with 0,0 at the center
43
+ rx : j - cells / 2 ,
44
+ ry : i - rows / 2
45
+ } ;
46
+
47
+ // Create a clone of the now hidden main element that will be absolute positioned
48
+ // within a wrapper div off the -left and -top equal to size of our pieces
35
49
el
36
50
. clone ( )
37
- . appendTo ( 'body' )
38
- . wrap ( '<div></div>' )
51
+ . appendTo ( 'body' )
52
+ . wrap ( '<div></div>' )
39
53
. css ( {
40
54
position : 'absolute' ,
41
55
visibility : 'visible' ,
42
- left : - j * ( width / cells ) ,
43
- top : - i * ( height / rows )
56
+ left : - j * width ,
57
+ top : - i * height
44
58
} )
59
+
60
+ // select the wrapper - make it overflow: hidden and absolute positioned based on
61
+ // where the original was located +left and +top equal to the size of pieces
45
62
. parent ( )
46
- . addClass ( 'ui-effects-explode' )
63
+ . addClass ( 'ui-effects-explode' )
47
64
. css ( {
48
65
position : 'absolute' ,
49
66
overflow : 'hidden' ,
50
- width : width / cells ,
51
- height : height / rows ,
52
- left : offset . left + j * ( width / cells ) + ( o . mode == ' show' ? ( j - Math . floor ( cells / 2 ) ) * ( width / cells ) : 0 ) ,
53
- top : offset . top + i * ( height / rows ) + ( o . mode == ' show' ? ( i - Math . floor ( rows / 2 ) ) * ( height / rows ) : 0 ) ,
54
- opacity : mode == ' show' ? 0 : 1
67
+ width : width ,
68
+ height : height ,
69
+ left : pos . left + ( show ? pos . rx * width : 0 ) ,
70
+ top : pos . top + ( show ? pos . ry * height : 0 ) ,
71
+ opacity : show ? 0 : 1
55
72
} ) . animate ( {
56
- left : offset . left + j * ( width / cells ) + ( o . mode == ' show' ? 0 : ( j - Math . floor ( cells / 2 ) ) * ( width / cells ) ) ,
57
- top : offset . top + i * ( height / rows ) + ( o . mode == ' show' ? 0 : ( i - Math . floor ( rows / 2 ) ) * ( height / rows ) ) ,
58
- opacity : mode == ' show' ? 1 : 0
59
- } , o . duration || 500 , childComplete ) ;
73
+ left : pos . left + ( show ? 0 : pos . rx * width ) ,
74
+ top : pos . top + ( show ? 0 : pos . ry * height ) ,
75
+ opacity : show ? 1 : 0
76
+ } , o . duration || 500 , o . easing , childComplete ) ;
60
77
}
61
78
}
62
79
@@ -69,9 +86,11 @@ $.effects.explode = function( o ) {
69
86
}
70
87
71
88
function animComplete ( ) {
72
- el . css ( { visibility : 'visible' } ) ;
89
+ el . css ( {
90
+ visibility : 'visible'
91
+ } ) ;
73
92
$ ( peices ) . remove ( ) ;
74
- if ( mode != ' show' ) {
93
+ if ( ! show ) {
75
94
el . hide ( ) ;
76
95
}
77
96
if ( $ . isFunction ( o . complete ) ) {
0 commit comments