-
Notifications
You must be signed in to change notification settings - Fork 0
/
SlideShow.js
executable file
·97 lines (84 loc) · 2.31 KB
/
SlideShow.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
/**
* SlideShow
* requirements: MooTools 1.2
*/
var SlideShow = new Class({
Implements: [Events, Options],
options: {
fadeOut: false,
fxDuration: 500,
fxTransition: 'quart:out',
interval: 5000,
// onChange: $empty();
showTitle: false
},
initialize: function(element, options)
{
this.element = $(element);
this.setOptions(options);
this.current = 0;
this.images = this.getImages();
this.initImages();
if(this.options.showTitle)
{
this.title = new Element('p', {
'class' : 'title'
}).inject(this.element);
this.setTitle();
}
this.slide.periodical(this.options.interval, this);
},
change: function()
{
this.fireEvent('change');
},
getImages: function()
{
return this.element.getElements('img');
},
initImages: function()
{
this.images.each(function(img, i){
img.setStyles({
opacity: i == 0 ? 1 : 0,
zIndex: i == 0 ? 1 : 0
});
});
},
slide: function()
{
var next = this.current + 1 < this.images.length ? this.current + 1 : 0;
this.images[next].setStyles({
opacity: 0,
zIndex: 2
});
if(this.options.fadeOut)
{
new Fx.Tween(this.images[this.current], {
duration: this.options.fxDuration,
transition: this.options.fxTransition
}).start('opacity', 0);
}
new Fx.Tween(this.images[next], {
duration: this.options.fxDuration,
transition: this.options.fxTransition
}).start('opacity', 1).chain(function(){
this.images[this.current].setStyles({
opacity: 0,
zIndex: 0
});
this.images[next].setStyle('z-index', 1);
this.current = next;
this.setTitle();
}.bind(this));
this.change();
},
setTitle: function()
{
if(!this.options.showTitle)
{
return;
}
this.title.set('html', this.images[this.current].get('title'));
}
});