-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
156 lines (129 loc) · 3.36 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
function getByClass(oParent,sClass){
var oEle=oParent.getElementsByTagName("*");
var aResult=[];
for(var i=0;i<oEle.length;i++)
{
if(oEle[i].className==sClass)
aResult.push(oEle)
}
return aResult;
}
var oPic=document.getElementById("picBox");
var sDiv=document.getElementById("small_div");
var oSimg=sDiv.getElementsByTagName("img");
var arr=[];
var clur=0;
var timer=null;
arr[0]="1.jpg";
arr[1]="2.jpg";
arr[2]="3.jpg";
arr[3]="4.jpg";
//还有一些bug 。比如移动到小图上清除定时器,移出后开启定时器;鼠标移动的时候显示多个小三角
/*var oSpan=document.createElement("span");
oSpan.className="sanjiao";
oSimg[clur].parentNode.appendChild(oSpan);
timer=setInterval(function(){
for(var i=0;i<oSimg.length;i++)
{
if(oSimg[i].parentNode.childNodes.length!=5)
{
var delSpan=sDiv.getElementsByTagName("span");
// alert(delSpan);
// debugger;
oSimg[i].parentNode.removeChild(oSimg[i].parentNode.lastChild);
}
}
if(clur==arr.length-1)
{clur=0;}
else
{clur+=1;}
var oSpan=document.createElement("span");
oSpan.className="sanjiao";
oSimg[clur].parentNode.appendChild(oSpan);
oPic.src="image/"+arr[clur];
},3000);
// 绘制三角形并使其跟随鼠标移动
for(var i=0;i<oSimg.length;i++)
{
oSimg[i].i=i;
oSimg[i].onmouseover=function(){
// clearInterval(timer);
var oSpan=document.createElement("span");
oSpan.className="sanjiao";
oSimg[this.i].parentNode.appendChild(oSpan);
oPic.src="image/"+(this.i+1)+".jpg";
};
oSimg[i].onmouseout=function(){
oSimg[this.i].parentNode.removeChild(oSimg[this.i].nextSibling.nextSibling.nextSibling.nextSibling);
};
}*/
// var oSpan=document.createElement("span");
// oSpan.className="sanjiao";
// oSimg[clur].parentNode.appendChild(oSpan);
//这里是用JS配合hover事件来实现的
var aSpan=sDiv.getElementsByTagName('span');
aSpan[0].style.opacity="1";
aSpan[0].style.filter="alpha(opacity:100);";
timer=setInterval(function(){
// alert(clur);
if(clur<arr.length)
{
aSpan[clur].style.opacity="0";
aSpan[clur].style.filter="alpha(opacity:0);";
}
else if(clur=0)
{
aSpan[3].style.opacity="0";
aSpan[3].style.filter="alpha(opacity:0);";
}
if(clur==arr.length-1)
{clur=0;}
else
{clur+=1;}
oPic.src="image/"+arr[clur];
aSpan[clur].style.opacity="1";
aSpan[clur].style.filter="alpha(opacity:100);";
},3000);
// 绘制三角形并使其跟随鼠标移动
for(var i=0;i<oSimg.length;i++)
{
oSimg[i].i=i;
oSimg[i].onmouseover=function(){
clearInterval(timer);
for(var j=0;j<oSimg.length;j++)
{
aSpan[j].style.opacity="0";
aSpan[j].style.filter="alpha(opacity:0);";
aSpan[this.i].style.opacity="1";
aSpan[this.i].style.filter="alpha(opacity:100);";
}
oPic.src="image/"+(this.i+1)+".jpg";
};
oSimg[i].onmouseout=function(){
for(var j=0;j<oSimg.length;j++)
{
aSpan[j].style.opacity="0";
aSpan[j].style.filter="alpha(opacity:0);";
}
timer=setInterval(function(){
// alert(clur);
if(clur<arr.length)
{
aSpan[clur].style.opacity="0";
aSpan[clur].style.filter="alpha(opacity:0);";
}
else if(clur=0)
{
aSpan[3].style.opacity="0";
aSpan[3].style.filter="alpha(opacity:0);";
}
if(clur==arr.length-1)
{clur=0;}
else
{clur+=1;}
oPic.src="image/"+arr[clur];
aSpan[clur].style.opacity="1";
aSpan[clur].style.filter="alpha(opacity:100);";
},3000);
};
}