1
|
|
|
/*! |
2
|
|
|
* jQuery UI Effects Bounce 1.12.1 |
3
|
|
|
* http://jqueryui.com |
4
|
|
|
* |
5
|
|
|
* Copyright jQuery Foundation and other contributors |
6
|
|
|
* Released under the MIT license. |
7
|
|
|
* http://jquery.org/license |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
//>>label: Bounce Effect |
11
|
|
|
//>>group: Effects |
12
|
|
|
//>>description: Bounces an element horizontally or vertically n times. |
13
|
|
|
//>>docs: http://api.jqueryui.com/bounce-effect/ |
14
|
|
|
//>>demos: http://jqueryui.com/effect/ |
15
|
|
|
|
16
|
|
|
( function( factory ) { |
17
|
|
|
if ( typeof define === "function" && define.amd ) { |
18
|
|
|
|
19
|
|
|
// AMD. Register as an anonymous module. |
20
|
|
|
define( [ |
21
|
|
|
"jquery", |
22
|
|
|
"../version", |
23
|
|
|
"../effect" |
24
|
|
|
], factory ); |
25
|
|
|
} else { |
26
|
|
|
|
27
|
|
|
// Browser globals |
28
|
|
|
factory( jQuery ); |
29
|
|
|
} |
30
|
|
|
}( function( $ ) { |
31
|
|
|
|
32
|
|
|
return $.effects.define( "bounce", function( options, done ) { |
33
|
|
|
var upAnim, downAnim, refValue, |
34
|
|
|
element = $( this ), |
35
|
|
|
|
36
|
|
|
// Defaults: |
37
|
|
|
mode = options.mode, |
38
|
|
|
hide = mode === "hide", |
39
|
|
|
show = mode === "show", |
40
|
|
|
direction = options.direction || "up", |
41
|
|
|
distance = options.distance, |
42
|
|
|
times = options.times || 5, |
43
|
|
|
|
44
|
|
|
// Number of internal animations |
45
|
|
|
anims = times * 2 + ( show || hide ? 1 : 0 ), |
46
|
|
|
speed = options.duration / anims, |
47
|
|
|
easing = options.easing, |
48
|
|
|
|
49
|
|
|
// Utility: |
50
|
|
|
ref = ( direction === "up" || direction === "down" ) ? "top" : "left", |
51
|
|
|
motion = ( direction === "up" || direction === "left" ), |
52
|
|
|
i = 0, |
53
|
|
|
|
54
|
|
|
queuelen = element.queue().length; |
55
|
|
|
|
56
|
|
|
$.effects.createPlaceholder( element ); |
57
|
|
|
|
58
|
|
|
refValue = element.css( ref ); |
59
|
|
|
|
60
|
|
|
// Default distance for the BIGGEST bounce is the outer Distance / 3 |
61
|
|
|
if ( !distance ) { |
62
|
|
|
distance = element[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ( show ) { |
66
|
|
|
downAnim = { opacity: 1 }; |
67
|
|
|
downAnim[ ref ] = refValue; |
68
|
|
|
|
69
|
|
|
// If we are showing, force opacity 0 and set the initial position |
70
|
|
|
// then do the "first" animation |
71
|
|
|
element |
72
|
|
|
.css( "opacity", 0 ) |
73
|
|
|
.css( ref, motion ? -distance * 2 : distance * 2 ) |
74
|
|
|
.animate( downAnim, speed, easing ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// Start at the smallest distance if we are hiding |
78
|
|
|
if ( hide ) { |
79
|
|
|
distance = distance / Math.pow( 2, times - 1 ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
downAnim = {}; |
83
|
|
|
downAnim[ ref ] = refValue; |
84
|
|
|
|
85
|
|
|
// Bounces up/down/left/right then back to 0 -- times * 2 animations happen here |
86
|
|
|
for ( ; i < times; i++ ) { |
87
|
|
|
upAnim = {}; |
88
|
|
|
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; |
89
|
|
|
|
90
|
|
|
element |
91
|
|
|
.animate( upAnim, speed, easing ) |
92
|
|
|
.animate( downAnim, speed, easing ); |
93
|
|
|
|
94
|
|
|
distance = hide ? distance * 2 : distance / 2; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// Last Bounce when Hiding |
98
|
|
|
if ( hide ) { |
99
|
|
|
upAnim = { opacity: 0 }; |
100
|
|
|
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; |
101
|
|
|
|
102
|
|
|
element.animate( upAnim, speed, easing ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
element.queue( done ); |
106
|
|
|
|
107
|
|
|
$.effects.unshift( element, queuelen, anims + 1 ); |
108
|
|
|
} ); |
109
|
|
|
|
110
|
|
|
} ) ); |
111
|
|
|
|