-
Notifications
You must be signed in to change notification settings - Fork 2
/
rotator.js
57 lines (38 loc) · 989 Bytes
/
rotator.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
(function($){
$.fn.rotator = function(options) {
// Options. Use empty object so we don't overwrite our defaults
var opts = $.extend({}, defaults, options);
// Set other essential values
var current = 1;
var children = this.children(opts.sub_selector);
var total = children.length;
// Hide all "rotate" divs
children.hide();
// Get the first rotate div to show
var $cur = children.first();
var $this = this;
$cur.fadeIn();
function rotate_this()
{
$cur.stop().fadeOut(opts.transition_speed, function(){
// See if we're at the end
if (current == total) {
$cur = children.first();
current = 0;
} else
$cur = $cur.next();
$cur.fadeIn(opts.transition_speed);
current++;
setTimeout(rotate_this,opts.speed);
});
}
// Start it
setTimeout(rotate_this,opts.speed);
return this;
};
var defaults = $.fn.defaults = {
speed: 3e3,
transition_speed: 500,
sub_selector: '.rotate'
};
})(jQuery);