Javascript Simple PhotoSlider


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
/* 
* Author: Zeuxis Lo
* Remark: <div id="Image1"></div>
*/

var PhotoSlider = function() {
this.currentIndex = 0;
this.timerId;

this.init = function(settings) {
var self = this;

this.timerId = setInterval(function() {
code = []
code.push('<a href="' + settings.bigPhoto[self.currentIndex] + '" target="_blank">');
code.push('<img src="' + settings.smallPhoto[self.currentIndex] + '" name="Image1" width="' + settings.width + '" height="' + settings.height + '" border="0">');
code.push('</a>');

document.getElementById(settings.id).innerHTML = code.join('')

if (self.currentIndex++ >= settings.smallPhoto.length - 1) {
self.currentIndex = 0;
!settings.loop && self.clearTimer()
}
}, settings.speed)
}

this.clearTimer = function() {
clearInterval(this.timerId);
}
}

new PhotoSlider().init({
id: 'Image1', // 插入頁面中的什麼位置,以 id="xxx" 定位
smallPhoto: ["01/1s.jpg","01/2s.jpg","01/3s.jpg","01/4s.jpg","01/5s.jpg"], // 小圖位置
bigPhoto: ["01/1.jpg","01/2.jpg","01/3.jpg","01/4.jpg","01/5.jpg"], // 大圖位置 (與小圖相對應)
speed: 1000*2, // 播放速度
width: 476, // 圖片寬度
height: 300, // 圖片高度
loop: true // 是否循環顯示
})