-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.lavaLamp.js
More file actions
95 lines (77 loc) · 1.78 KB
/
Copy pathjquery.lavaLamp.js
File metadata and controls
95 lines (77 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* jQuery lavaLamp plugin
* Version: 0.1.0
* Author: Steffen Dietz
*
* Rewritten b\c old plugin also triggered on nested lists, which is not always useful.
*
*/
(function($) {
$.fn.lavaLamp = function(o) {
/*
* SETUP OBJECT
* TODO: Check if possible to provide less vars but put them in the lavaLamp call
* critical vars: excludeEl, outOfBounds,
*/
o = $.extend({ fx: 'swing',
speed: 300,
elem: $('li',this),
activeEl: $('li.active',this),
excludeEl: $('li>ul>li'),
slider: $('<li class="back"><div class="left"></div></li>'),
appendSlider: true,
click: function(){}
},
o || {}
);
return this.each(function() {
/*
* SETUP lavaLamp
*
* TODO: if has active then outOfBounds has to be false to have the indicator going
* there on init - u know what i mean?!
* best way - don't provide outOfBounds - just check for activeEl ?!
*/
var me = $(this),
noop = function(){},
s = o.appendSlider ? $(o.slider).appendTo(me) : o.slider,
curr = o.activeEl.length ? move(o.activeEl) : move(null);
$(o.elem).not(o.excludeEl).not(s).hover(
function() {
move(this);
},
noop
);
$(this).hover(
noop,
function() {
move(curr);
}
);
$(o.elem).click(function(e) {
setCurr(this);
return o.click.apply(this, [e, this]);
});
function move(el) {
if(el != null){
s.each(function() {
$(this).dequeue();
}).animate({
width: $(el).width(),
left: $(el).position().left
}, o.speed, o.fx);
}
else
{
s.each(function() {
$(this).dequeue();
}).animate({
width: 0,
left: 0
},o.speed, o.fx);
}
return el;
};
});
};
})(jQuery);