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