-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.mouseover-gallery.js
50 lines (45 loc) · 1.32 KB
/
jquery.mouseover-gallery.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
/**
* jQuery Mouseover Gallery
* Copyright 2011 Dan Drinkard, <[email protected]>
* MIT License
*/
(function($){
$.fn.mouseoverGallery = function(opts){
var el = $(this)
, els
, options = {}
, defaults = {
'selector': 'img'
}
, init = function(){
options = $.extend(options, defaults, opts);
els = el.find(options.selector);
if(!els.length > 1){
window.console && console.log && console.log(el.selector + ': not enough children matching selector "' + options.selector + '" found, aborting.');
return el;
}
els.eq(0).siblings().hide();
el.hover(function(evt){
el.data('active', true);
}, function(evt){
el.data('active', false);
els.eq(0).show().siblings().hide();
});
el.mousemove(handler);
return el;
}
, handler = function(evt){
if(el.data('active')){
var mouseX = evt.pageX
, elX = el.offset().left
, elW = el.width()
, size = els.length
, imgToShow = Math.floor(((mouseX - elX) / elW) * size)
;
els.eq(imgToShow).show().siblings().hide();
}
}
;
return init();
}
})(jQuery);