-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.scroller.js
63 lines (50 loc) · 1.52 KB
/
jquery.scroller.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
(function($) {
var elements = [];
var t = [];
$.fn.scroller = function(options) {
var container = $(this).addClass('ui-scroller');
var settings = $.extend({
delay: 2000,
speed: 'slow'
}, options);
container.each(function(i) {
this.settings = settings;
this.pause = false;
$(this).hover(function() { pause(true, i); }, function() { pause(false, i); });
$('> ul', this).bind('mouseover', function(evt) {
if($(evt.target).is('li')) {
$(evt.target).addClass('hover');
}
}).bind('mouseout', function(evt) {
if($(evt.target).is('li')) {
$(evt.target).removeClass('hover');
}
});
elements.push(this);
t.push(setTimeout(function() { scroll(i) }, settings.delay));
});
return container;
};
function pause(status, index) {
var elm = elements[index];
elm.pause = status;
if(elm.pause) {
clearTimeout(t[index]);
var ul = $('> ul', elm)[0];
$(ul).stop().animate({ top: '0px' }, 250);
} else {
t[index] = setTimeout(function() { scroll(index) }, elm.settings.delay / 2);
}
}
function scroll(index) {
var elm = elements[index];
var ul = $('> ul', elm)[0];
var first_item = $('> li:first-child', ul);
var shift = first_item.height();
$(ul).animate({ top: '-' + shift + 'px' }, elm.settings.speed, function() {
t[index] = setTimeout(function() { scroll(index) }, elm.settings.delay);
first_item.remove();
$(ul).css('top', '0px').find('> li:last-child').after(first_item.clone());
});
}
})(jQuery);