@@ -18,60 +18,77 @@ $.effects.effect.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
+ pieces = [ ] ,
32
+
33
+ // loop
34
+ i , j , left , top , mx , my ;
31
35
32
36
// clone the element for each row and cell.
33
- for ( var i = 0 ; i < rows ; i ++ ) { // =
34
- for ( var j = 0 ; j < cells ; j ++ ) { // ||
37
+ for ( i = 0 ; i < rows ; i ++ ) { // ===>
38
+ top = offset . top + i * height ;
39
+ my = i - ( rows - 1 ) / 2 ;
40
+
41
+ for ( j = 0 ; j < cells ; j ++ ) { // |||
42
+ left = offset . left + j * width ;
43
+ mx = j - ( cells - 1 ) / 2 ;
44
+
45
+ // Create a clone of the now hidden main element that will be absolute positioned
46
+ // within a wrapper div off the -left and -top equal to size of our pieces
35
47
el
36
48
. clone ( )
37
- . appendTo ( 'body' )
38
- . wrap ( '<div></div>' )
49
+ . appendTo ( 'body' )
50
+ . wrap ( '<div></div>' )
39
51
. css ( {
40
52
position : 'absolute' ,
41
53
visibility : 'visible' ,
42
- left : - j * ( width / cells ) ,
43
- top : - i * ( height / rows )
54
+ left : - j * width ,
55
+ top : - i * height
44
56
} )
57
+
58
+ // select the wrapper - make it overflow: hidden and absolute positioned based on
59
+ // where the original was located +left and +top equal to the size of pieces
45
60
. parent ( )
46
- . addClass ( 'ui-effects-explode' )
61
+ . addClass ( 'ui-effects-explode' )
47
62
. css ( {
48
63
position : 'absolute' ,
49
64
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
65
+ width : width ,
66
+ height : height ,
67
+ left : left + ( show ? mx * width : 0 ) ,
68
+ top : top + ( show ? my * height : 0 ) ,
69
+ opacity : show ? 0 : 1
55
70
} ) . 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 ) ;
71
+ left : left + ( show ? 0 : mx * width ) ,
72
+ top : top + ( show ? 0 : my * height ) ,
73
+ opacity : show ? 1 : 0
74
+ } , o . duration || 500 , o . easing , childComplete ) ;
60
75
}
61
76
}
62
77
63
78
// children animate complete:
64
79
function childComplete ( ) {
65
- peices . push ( this ) ;
66
- if ( peices . length == rows * cells ) {
80
+ pieces . push ( this ) ;
81
+ if ( pieces . length == rows * cells ) {
67
82
animComplete ( ) ;
68
83
}
69
84
}
70
85
71
86
function animComplete ( ) {
72
- el . css ( { visibility : 'visible' } ) ;
73
- $ ( peices ) . remove ( ) ;
74
- if ( mode != 'show' ) {
87
+ el . css ( {
88
+ visibility : 'visible'
89
+ } ) ;
90
+ $ ( pieces ) . remove ( ) ;
91
+ if ( ! show ) {
75
92
el . hide ( ) ;
76
93
}
77
94
if ( $ . isFunction ( o . complete ) ) {
0 commit comments