-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (49 loc) · 1.17 KB
/
index.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
var oContainer = document.getElementById('container');
var oTab = document.getElementById('tab');
var aLi = oTab.getElementsByTagName('li');
var oContent = document.getElementById('content');
var aImg = oContent.getElementsByTagName('img');
var oPrev = document.getElementById('prev');
var oNext = document.getElementById('next');
var index = 0;
for(var i=0; i<aLi.length; i++){
aLi[i].index = i;
aLi[i].onmouseover = function(){
index = this.index;
switchImg( this.index );
};
}
function switchImg(idx){
for(var i=0; i<aLi.length; i++){
aLi[i].className = "";
aImg[i].className = "";
}
// elem.className = "selected";
aLi[idx].className = 'selected';
aImg[idx].className = 'selected';
}
oPrev.onclick = function(){
index--;
if(index < 0){
index = aLi.length - 1;
}
switchImg( index );
};
oNext.onclick = function(){
index++;
if(index > aLi.length - 1){
index = 0;
}
switchImg( index );
};
var timer = setInterval(function(){
oNext.onclick();
}, 2000);
oContainer.onmouseover = function(){
clearInterval(timer);
};
oContainer.onmouseout = function(){
timer = setInterval(function(){
oNext.onclick();
}, 2000);
};