forked from zetalab/jquery-karussell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.plugin.karussell-1.0.js
47 lines (41 loc) · 1.33 KB
/
jquery.plugin.karussell-1.0.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
(function( $ ) {
$.fn.karussell = function(params) {
var defaults = {
wipetime: 500,
pause: 2000
};
var config = $.extend(defaults, params);
var item = 0;
return this.each(function() {
var $this = $(this);
var totalwidth = 0;
var elements = $this.children();
for (var n = 0; n < elements.length; n++) {
totalwidth += $(elements[n]).width();
}
var elemwidth = totalwidth / elements.length;
var height = $(elements[0]).height();
var e = $('<div>').attr('id', 'jk_elements' + item.toString())
.width(totalwidth)
.height(height)
.css('position', 'relative');
e.append(elements.detach());
var t = $('<div>').attr('id', 'jk_mask' + item.toString())
.width(elemwidth)
.height(height)
.css('overflow', 'hidden');
t.append(e);
$this.append(t);
item++;
animate = function(duration, container) {
var offset = (-elemwidth).toString() + "px";
container.animate({'left': offset}, duration, function () {
container.css({'left': 0});
var first = container.children(':first').detach();
container.append(first);
});
}
setInterval(function () { animate(config.wipetime, e); }, config.pause);
}); // return
};
})( jQuery );