forked from jsor/jcarousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.jcarousel-autoscroll.js
59 lines (51 loc) · 1.64 KB
/
jquery.jcarousel-autoscroll.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
/*! jCarousel - v0.3.0 - 2014-01-09
* http://sorgalla.com/jcarousel
* Copyright (c) 2014 Jan Sorgalla; Licensed MIT */
(function($) {
'use strict';
$.jCarousel.plugin('jcarouselAutoscroll', {
_options: {
target: '+=1',
interval: 3000,
autostart: true
},
_timer: null,
_init: function () {
this.onDestroy = $.proxy(function() {
this._destroy();
this.carousel()
.one('jcarousel:createend', $.proxy(this._create, this));
}, this);
this.onAnimateEnd = $.proxy(this.start, this);
},
_create: function() {
this.carousel()
.one('jcarousel:destroy', this.onDestroy);
if (this.options('autostart')) {
this.start();
}
},
_destroy: function() {
this.stop();
this.carousel()
.off('jcarousel:destroy', this.onDestroy);
},
start: function() {
this.stop();
this.carousel()
.one('jcarousel:animateend', this.onAnimateEnd);
this._timer = setTimeout($.proxy(function() {
this.carousel().jcarousel('scroll', this.options('target'));
}, this), this.options('interval'));
return this;
},
stop: function() {
if (this._timer) {
this._timer = clearTimeout(this._timer);
}
this.carousel()
.off('jcarousel:animateend', this.onAnimateEnd);
return this;
}
});
}(jQuery));