forked from richhollis/vticker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.vticker.js
executable file
·142 lines (125 loc) · 3.55 KB
/
jquery.vticker.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* vertical news ticker
* Tadas Juozapaitis ( kasp3rito [eta] gmail (dot) com )
* http://www.jugbit.com/jquery-vticker-vertical-news-ticker/
*/
/*
Modified by Richard Hollis
*/
(function($){
var defaults = {
speed: 700,
pause: 4000,
showItems: 3,
mousePause: true,
isPaused: false,
height: 0
};
var methods = {
options: null,
maxHeight: 0,
obj: null,
animating: false,
init: function(options) {
var options = methods.options = $.extend(defaults, options);
var obj = methods.obj = $(this);
var maxHeight = 0;
obj.css({overflow: 'hidden', position: 'relative'})
.children('ul').css({position: 'absolute', margin: 0, padding: 0})
.children('li').css({margin: 0, padding: 0});
if(options.height == 0)
{
obj.children('ul').children('li').each(function(){
if($(this).height() > maxHeight)
{
methods.maxHeight = $(this).height();
}
});
obj.children('ul').children('li').each(function(){
$(this).height(maxHeight);
});
obj.height(maxHeight * options.showItems);
}
else
{
obj.height(options.height);
}
var interval = setInterval(function(){
methods.nextUsePause();
}, options.pause);
if(options.mousePause)
{
obj.bind("mouseenter",function(){
methods.pause(true);
}).bind("mouseleave",function(){
methods.pause(false);
});
}
},
pause: function(state) {
methods.options.isPaused = state;
},
moveUp: function(obj2, height, options, moveOptions){
var obj = obj2.children('ul');
var clone = obj.children('li:first').clone(true);
if(options.height > 0)
{
height = obj.children('li:first').height();
}
if(moveOptions && moveOptions.animate) {
methods.animating = true;
obj.animate({top: '-=' + height + 'px'}, options.speed, function() {
$(this).children('li:first').remove();
$(this).css('top', '0px');
methods.animating = false;
});
} else {
obj.children('li:first').remove();
obj.css('top', '0px');
}
clone.appendTo(obj);
},
moveDown: function(obj2, height, options, moveOptions){
var obj = obj2.children('ul');
var clone = obj.children('li:last').clone(true);
if(options.height > 0)
{
height = obj.children('li:first').height();
}
obj.css('top', '-' + height + 'px')
.prepend(clone);
if(moveOptions && moveOptions.animate) {
if(methods.animating) return;
methods.animating = true;
obj.animate({top: 0}, options.speed, function() {
$(this).children('li:last').remove();
methods.animating = false;
});
} else {
obj.children('li:last').remove();
obj.css('top', '0px');
}
},
nextUsePause: function() {
if(methods.options.isPaused) return;
methods.next({animate: true});
},
next: function(options) {
if(methods.animating) return false;
methods.moveUp(methods.obj, methods.maxHeight, methods.options, options);
},
prev: function(options) {
if(methods.animating) return false;
methods.moveDown(methods.obj, methods.maxHeight, methods.options, options);
}
};
$.fn.vTicker = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.vTicker' );
}
};
})(jQuery);