-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtools.scrollable.autoscroll.js
97 lines (74 loc) · 2.12 KB
/
tools.scrollable.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
/**
* jQuery TOOLS plugin :: scrollable.autoscroll 1.0.1
*
* Copyright (c) 2009 Tero Piirainen
* http://flowplayer.org/tools/scrollable.html#autoscroll
*
* Dual licensed under MIT and GPL 2+ licenses
* http://www.opensource.org/licenses
*
* Launch : September 2009
* Date: ${date}
* Revision: ${revision}
*/
(function($) {
var t = $.tools.scrollable;
t.plugins = t.plugins || {};
t.plugins.autoscroll = {
version: '1.0.1',
conf: {
autoplay: true,
interval: 3000,
autopause: true,
steps: 1,
api: false
}
};
// jQuery plugin implementation
$.fn.autoscroll = function(conf) {
if (typeof conf == 'number') {
conf = {interval: conf};
}
var opts = $.extend({}, t.plugins.autoscroll.conf), ret;
$.extend(opts, conf);
this.each(function() {
var api = $(this).scrollable();
if (api) { ret = api; }
// interval stuff
var timer, hoverTimer, stopped = true;
api.play = function() {
// do not start additional timer if already exists
if (timer) { return; }
stopped = false;
// construct new timer
timer = setInterval(function() {
api.move(opts.steps);
}, opts.interval);
api.move(opts.steps);
};
api.pause = function() {
timer = clearInterval(timer);
};
// when stopped - mouseover won't restart
api.stop = function() {
api.pause();
stopped = true;
};
/* when mouse enters, autoscroll stops */
if (opts.autopause) {
api.getRoot().add(api.getNaviButtons()).hover(function() {
api.pause();
clearInterval(hoverTimer);
}, function() {
if (!stopped) {
hoverTimer = setTimeout(api.play, opts.interval);
}
});
}
if (opts.autoplay) {
setTimeout(api.play, opts.interval);
}
});
return opts.api ? ret : this;
};
})(jQuery);