forked from spreadthesource/jquery-featurify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
featurify.js
104 lines (77 loc) · 1.59 KB
/
featurify.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
(function($) {
$.fn.featurify = function(options) {
var that = this;
$(window).load(function() {
var settings = {
transition : 750,
pause : 5000,
directionIn : 1,
directionOut : -1,
};
if (options) $.extend(settings, options);
var featuresWidth = that.width(),
ul = that.find("ul"),
li = ul.find("li"),
liWidth = li.width(),
t = undefined,
on = false;
that.css({
overflow:"hidden"
});
li.hide().first().show();
var featuresHeight = ul.height();
ul.css({
width: featuresWidth + "px",
position: "relative",
height: featuresHeight + "px",
});
var position = li.first().position();
li.css({
position : "absolute",
width: liWidth + "px"
});
var loop = function() {
if (on) return;
on = true;
var li = that.find("li"),
first = li.first(),
next = first.next();
first.css("left", position.left + "px")
.show()
.clone()
.hide()
.insertAfter(li.last());;
next.css({
"left" : settings.directionIn * featuresWidth + "px",
opacity : 0
})
.show();
first.animate({
opacity: 0,
left: settings.directionOut * featuresWidth + "px"
},
settings.transition,
function() {
$(this).remove();
});
next.animate({
opacity: 1,
left: position.left + "px",
},
settings.transition);
setTimeout(function() { on = false; }, settings.transition);
if (t)
t = setTimeout(function() { loop(); }, settings.pause);
}
that.hover(function() {
clearTimeout(t);
t = undefined;
},
function() {
t = setTimeout(function() { loop(); }, settings.transition);
});
t = setTimeout(function() { loop(); }, settings.pause);
});
return this;
};
})(jQuery);