|
12 | 12 | */ |
13 | 13 | (function( $, undefined ) { |
14 | 14 |
|
15 | | -$.effects.effect.bounce = function(o) { |
16 | | - |
17 | | - return this.queue( function( next ) { |
18 | | - var el = $( this ), |
19 | | - props = [ "position", "top", "bottom", "left", "right", "height", "width" ], |
20 | | - |
21 | | - // defaults: |
22 | | - mode = $.effects.setMode( el, o.mode || "effect" ), |
23 | | - hide = mode === "hide", |
24 | | - show = mode === "show", |
25 | | - direction = o.direction || "up", |
26 | | - distance = o.distance, |
27 | | - times = o.times || 5, |
28 | | - |
29 | | - // number of internal animations |
30 | | - anims = times * 2 + ( show || hide ? 1 : 0 ), |
31 | | - speed = o.duration / anims, |
32 | | - easing = o.easing, |
33 | | - |
34 | | - // utility: |
35 | | - ref = ( direction === "up" || direction === "down" ) ? "top" : "left", |
36 | | - motion = ( direction === "up" || direction === "left" ), |
37 | | - i, |
38 | | - upAnim, |
39 | | - downAnim, |
40 | | - |
41 | | - // we will need to re-assemble the queue to stack our animations in place |
42 | | - queue = el.queue(), |
43 | | - queuelen = queue.length; |
44 | | - |
45 | | - // Avoid touching opacity to prevent clearType and PNG issues in IE |
46 | | - if ( show || hide ) { |
47 | | - props.push( "opacity" ); |
48 | | - } |
49 | | - |
50 | | - $.effects.save( el, props ); |
51 | | - el.show(); |
52 | | - $.effects.createWrapper( el ); // Create Wrapper |
53 | | - |
54 | | - // default distance for the BIGGEST bounce is the outer Distance / 3 |
55 | | - if ( !distance ) { |
56 | | - distance = el[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3; |
57 | | - } |
58 | | - |
59 | | - if ( show ) { |
60 | | - downAnim = { opacity: 1 }; |
61 | | - downAnim[ ref ] = 0; |
62 | | - |
63 | | - // if we are showing, force opacity 0 and set the initial position |
64 | | - // then do the "first" animation |
65 | | - el.css( "opacity", 0 ) |
66 | | - .css( ref, motion ? -distance*2 : distance*2 ) |
67 | | - .animate( downAnim, speed, easing ); |
68 | | - } |
69 | | - |
70 | | - // start at the smallest distance if we are hiding |
71 | | - if ( hide ) { |
72 | | - distance = distance / Math.pow( 2, times - 1 ); |
73 | | - } |
74 | | - |
75 | | - downAnim = {}; |
| 15 | +$.effects.effect.bounce = function( o, next ) { |
| 16 | + var el = $( this ), |
| 17 | + props = [ "position", "top", "bottom", "left", "right", "height", "width" ], |
| 18 | + |
| 19 | + // defaults: |
| 20 | + mode = $.effects.setMode( el, o.mode || "effect" ), |
| 21 | + hide = mode === "hide", |
| 22 | + show = mode === "show", |
| 23 | + direction = o.direction || "up", |
| 24 | + distance = o.distance, |
| 25 | + times = o.times || 5, |
| 26 | + |
| 27 | + // number of internal animations |
| 28 | + anims = times * 2 + ( show || hide ? 1 : 0 ), |
| 29 | + speed = o.duration / anims, |
| 30 | + easing = o.easing, |
| 31 | + |
| 32 | + // utility: |
| 33 | + ref = ( direction === "up" || direction === "down" ) ? "top" : "left", |
| 34 | + motion = ( direction === "up" || direction === "left" ), |
| 35 | + i, |
| 36 | + upAnim, |
| 37 | + downAnim, |
| 38 | + |
| 39 | + // we will need to re-assemble the queue to stack our animations in place |
| 40 | + queue = el.queue(), |
| 41 | + queuelen = queue.length; |
| 42 | + |
| 43 | + // Avoid touching opacity to prevent clearType and PNG issues in IE |
| 44 | + if ( show || hide ) { |
| 45 | + props.push( "opacity" ); |
| 46 | + } |
| 47 | + |
| 48 | + $.effects.save( el, props ); |
| 49 | + el.show(); |
| 50 | + $.effects.createWrapper( el ); // Create Wrapper |
| 51 | + |
| 52 | + // default distance for the BIGGEST bounce is the outer Distance / 3 |
| 53 | + if ( !distance ) { |
| 54 | + distance = el[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3; |
| 55 | + } |
| 56 | + |
| 57 | + if ( show ) { |
| 58 | + downAnim = { opacity: 1 }; |
76 | 59 | downAnim[ ref ] = 0; |
77 | | - // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here |
78 | | - for ( i = 0; i < times; i++ ) { |
79 | | - upAnim = {}; |
80 | | - upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; |
81 | | - |
82 | | - el.animate( upAnim, speed, easing ) |
83 | | - .animate( downAnim, speed, easing ); |
84 | | - |
85 | | - distance = hide ? distance * 2 : distance / 2; |
86 | | - } |
87 | 60 |
|
88 | | - // Last Bounce when Hiding |
| 61 | + // if we are showing, force opacity 0 and set the initial position |
| 62 | + // then do the "first" animation |
| 63 | + el.css( "opacity", 0 ) |
| 64 | + .css( ref, motion ? -distance*2 : distance*2 ) |
| 65 | + .animate( downAnim, speed, easing ); |
| 66 | + } |
| 67 | + |
| 68 | + // start at the smallest distance if we are hiding |
| 69 | + if ( hide ) { |
| 70 | + distance = distance / Math.pow( 2, times - 1 ); |
| 71 | + } |
| 72 | + |
| 73 | + downAnim = {}; |
| 74 | + downAnim[ ref ] = 0; |
| 75 | + // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here |
| 76 | + for ( i = 0; i < times; i++ ) { |
| 77 | + upAnim = {}; |
| 78 | + upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; |
| 79 | + |
| 80 | + el.animate( upAnim, speed, easing ) |
| 81 | + .animate( downAnim, speed, easing ); |
| 82 | + |
| 83 | + distance = hide ? distance * 2 : distance / 2; |
| 84 | + } |
| 85 | + |
| 86 | + // Last Bounce when Hiding |
| 87 | + if ( hide ) { |
| 88 | + upAnim = { opacity: 0 }; |
| 89 | + upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; |
| 90 | + |
| 91 | + el.animate( upAnim, speed, easing ); |
| 92 | + } |
| 93 | + |
| 94 | + el.queue( function( next ) { |
89 | 95 | if ( hide ) { |
90 | | - upAnim = { opacity: 0 }; |
91 | | - upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; |
92 | | - |
93 | | - el.animate( upAnim, speed, easing ); |
| 96 | + el.hide(); |
94 | 97 | } |
95 | | - |
96 | | - el.queue( function( next ) { |
97 | | - if ( hide ) { |
98 | | - el.hide(); |
99 | | - } |
100 | | - $.effects.restore( el, props ); |
101 | | - $.effects.removeWrapper( el ); |
102 | | - if ( o.complete ) { |
103 | | - o.complete.apply( el[ 0 ] ); |
104 | | - } |
105 | | - next(); |
106 | | - }); |
107 | | - |
108 | | - // inject all the animations we just queued to be first in line (after "inprogress") |
109 | | - if ( queuelen > 1) { |
110 | | - queue.splice.apply( queue, |
111 | | - [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) ); |
| 98 | + $.effects.restore( el, props ); |
| 99 | + $.effects.removeWrapper( el ); |
| 100 | + if ( o.complete ) { |
| 101 | + o.complete.apply( el[ 0 ] ); |
112 | 102 | } |
113 | 103 | next(); |
114 | | - |
115 | 104 | }); |
116 | 105 |
|
| 106 | + // inject all the animations we just queued to be first in line (after "inprogress") |
| 107 | + if ( queuelen > 1) { |
| 108 | + queue.splice.apply( queue, |
| 109 | + [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) ); |
| 110 | + } |
| 111 | + next(); |
| 112 | + |
117 | 113 | }; |
118 | 114 |
|
119 | 115 | })(jQuery); |
0 commit comments