-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprites2.js
77 lines (64 loc) · 2.88 KB
/
sprites2.js
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
/**
* Sprites2: animated CSS Sprites based navigation bars.
*
* Based on original A List Apart article by Dave Shea - http://www.alistapart.com/articles/sprites2
*
* version: 1.0.1
* released: February 26, 2009
* author: gonchuki
* url: http://blog.gonchuki.com
* git: http://github.com/gonchuki/sprites2-moo
*
* This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
* http://creativecommons.org/licenses/by-sa/3.0/
*/
var Sprites2 = new Class({
Implements: [Options],
options: {
item_selector: 'ul.nav a',
parent_selector: 'li',
mode: 'fade',
duration: 250
},
initialize: function(options) {
this.setOptions(options);
var self = this;
document.getElements(self.options.item_selector).each(function(item) {
var parent_element = item.getParent(self.options.parent_selector);
var fx_element = new Element('div', {
'class': 'effect',
'tween': { duration: self.options.duration }
}).inject(parent_element, 'top');
self.effects[self.options.mode].call(self, fx_element);
parent_element.addEvents({
mouseover: function() { if (!parent_element.hasClass('current')) self.show_fn(fx_element); },
mouseout: function() { if (!parent_element.hasClass('current')) { self.hide_fn(fx_element); fx_element.removeClass('mousedown'); }},
mousedown: function() { fx_element.addClass('mousedown'); },
mouseup: function() { fx_element.removeClass('mousedown'); },
mouseleave: function() { fx_element.removeClass('mousedown'); }
});
if (!parent_element.hasClass('current')) item.setStyle('background-image', 'none');
});
},
effects: {
fade: function(fx_element) {
fx_element.fade('hide');
this.show_fn = function(fx_element) { fx_element.fade('in'); };
this.hide_fn = function(fx_element) { fx_element.fade('out'); };
},
slide: function(fx_element) {
fx_element.store('height', fx_element.getSize().y).setStyle('height', 0);
this.show_fn = function(fx_element) { fx_element.tween('height', fx_element.retrieve('height')); };
this.hide_fn = function(fx_element) { fx_element.tween('height', 0); };
},
animate: function(fx_element) {
fx_element.setStyles({'height': 0, 'top': fx_element.retrieve('height', fx_element.getSize().y), 'opacity': 0})
.set('morph', {
'duration': this.options.duration / 2,
'onComplete': function() { if (fx_element.getSize().y === 0) fx_element.setStyles({'top': fx_element.retrieve('height'), 'opacity': 0}); }
});
this.show_fn = function(fx_element) { fx_element.morph({'height': fx_element.retrieve('height'), 'top': 0, 'opacity': 1}); };
this.hide_fn = function(fx_element) { fx_element.morph({'height': 0, 'opacity': 0.5}); };
}
}
});