1 /** |
|
2 * Interface Elements for jQuery |
|
3 * FX - bounce |
|
4 * |
|
5 * http://interface.eyecon.ro |
|
6 * |
|
7 * Copyright (c) 2006 Stefan Petre |
|
8 * Dual licensed under the MIT (MIT-LICENSE.txt) |
|
9 * and GPL (GPL-LICENSE.txt) licenses. |
|
10 * |
|
11 * |
|
12 */ |
|
13 |
|
14 /** |
|
15 * @name Bounce |
|
16 * @description makes the element to bounce |
|
17 * @param Integer hight the hight in pxels for element to jumps to |
|
18 * @param Function callback (optional) A function to be executed whenever the animation completes. |
|
19 * @type jQuery |
|
20 * @cat Plugins/Interface |
|
21 * @author Stefan Petre |
|
22 */ |
|
23 jQuery.fn.Bounce = function (hight, callback) { |
|
24 return this.queue('interfaceFX', function(){ |
|
25 if (!jQuery.fxCheckTag(this)) { |
|
26 jQuery.dequeue(this, 'interfaceFX'); |
|
27 return false; |
|
28 } |
|
29 var e = new jQuery.fx.iBounce(this, hight, callback); |
|
30 e.bounce(); |
|
31 }); |
|
32 }; |
|
33 jQuery.fx.iBounce = function (e, hight, callback) |
|
34 { |
|
35 var z = this; |
|
36 z.el = jQuery(e); |
|
37 z.el.show(); |
|
38 z.callback = callback; |
|
39 z.hight = parseInt(hight)||40; |
|
40 z.oldStyle = {}; |
|
41 z.oldStyle.position = z.el.css('position'); |
|
42 z.oldStyle.top = parseInt(z.el.css('top'))||0; |
|
43 z.oldStyle.left = parseInt(z.el.css('left'))||0; |
|
44 |
|
45 if (z.oldStyle.position != 'relative' && z.oldStyle.position != 'absolute') { |
|
46 z.el.css('position', 'relative'); |
|
47 } |
|
48 |
|
49 z.times = 5; |
|
50 z.cnt = 1; |
|
51 |
|
52 z.bounce = function () |
|
53 { |
|
54 z.cnt ++; |
|
55 z.e = new jQuery.fx( |
|
56 z.el.get(0), |
|
57 { |
|
58 duration: 120, |
|
59 complete : function () |
|
60 { |
|
61 z.e = new jQuery.fx( |
|
62 z.el.get(0), |
|
63 { |
|
64 duration: 80, |
|
65 complete : function () |
|
66 { |
|
67 z.hight = parseInt(z.hight/2); |
|
68 if (z.cnt <= z.times) |
|
69 z.bounce(); |
|
70 else { |
|
71 z.el.css('position', z.oldStyle.position).css('top', z.oldStyle.top + 'px').css('left', z.oldStyle.left + 'px'); |
|
72 jQuery.dequeue(z.el.get(0), 'interfaceFX'); |
|
73 if (z.callback && z.callback.constructor == Function) { |
|
74 z.callback.apply(z.el.get(0)); |
|
75 } |
|
76 } |
|
77 } |
|
78 }, |
|
79 'top' |
|
80 ); |
|
81 z.e.custom (z.oldStyle.top-z.hight, z.oldStyle.top); |
|
82 } |
|
83 }, |
|
84 'top' |
|
85 ); |
|
86 z.e.custom (z.oldStyle.top, z.oldStyle.top-z.hight); |
|
87 }; |
|
88 |
|
89 }; |
|