-
Notifications
You must be signed in to change notification settings - Fork 736
/
Copy pathjquery.jcarousel-autoscroll.js
110 lines (93 loc) · 2.97 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
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
/*! jCarousel - v0.3.9 - 2018-07-30
* http://sorgalla.com/jcarousel/
* Copyright (c) 2006-2018 Jan Sorgalla; Licensed MIT */
(function($, document) {
'use strict';
var hiddenProp,
visibilityChangeEvent,
visibilityChangeEventNames = {
hidden: 'visibilitychange',
mozHidden: 'mozvisibilitychange',
msHidden: 'msvisibilitychange',
webkitHidden: 'webkitvisibilitychange'
}
;
$.each(visibilityChangeEventNames, function(key, val) {
if (typeof document[key] !== 'undefined') {
hiddenProp = key;
visibilityChangeEvent = val;
return false;
}
});
$.jCarousel.plugin('jcarouselAutoscroll', {
_options: {
target: '+=1',
interval: 3000,
autostart: true,
method: 'scroll'
},
_timer: null,
_started: false,
_init: function () {
this.onDestroy = $.proxy(function() {
this._destroy();
this.carousel()
.one('jcarousel:createend', $.proxy(this._create, this));
}, this);
this.onAnimateEnd = $.proxy(this._start, this);
this.onVisibilityChange = $.proxy(function() {
if (document[hiddenProp]) {
this._stop();
} else {
this._start();
}
}, this);
},
_create: function() {
this.carousel()
.one('jcarousel:destroy', this.onDestroy);
$(document)
.on(visibilityChangeEvent, this.onVisibilityChange);
if (this.options('autostart')) {
this.start();
}
},
_destroy: function() {
this._stop();
this.carousel()
.off('jcarousel:destroy', this.onDestroy);
$(document)
.off(visibilityChangeEvent, this.onVisibilityChange);
},
_start: function() {
this._stop();
if (!this._started) {
return;
}
this.carousel()
.one('jcarousel:animateend', this.onAnimateEnd);
this._timer = setTimeout($.proxy(function() {
this.carousel().jcarousel(this.options('method'), 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;
},
start: function() {
this._started = true;
this._start();
return this;
},
stop: function() {
this._started = false;
this._stop();
return this;
}
});
}(jQuery, document));