-
Notifications
You must be signed in to change notification settings - Fork 0
/
20161112轮播图无缝连接.html
151 lines (147 loc) · 3.86 KB
/
20161112轮播图无缝连接.html
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
*{
padding: 0;
margin: 0;
}
ul,ol{
list-style: none;
}
#container{
width: 500px;
height: 400px;
position: relative;
top: 120px;
left: 200px;
overflow: hidden;
}
#content{
height: 400px;
position: absolute;
left: 0;
}
#content div{
height: 400px;
width: 500px;
float: left;
/*position: absolute;*/
/*left: 0;*/
/*top: 0;*/
}
#tab{
position: absolute;
right: 20px;
bottom: 20px;
z-index: 999999;
}
#tab li{
height: 20px;
width: 20px;
line-height: 20px;
text-align: center;
background-color: black;
color: #ffffff;
float: left;
margin-right: 5px;
cursor: pointer;
}
#tab .selected{
background-color:orange ;
}
#arrow{
position: absolute;
left: 20px;
bottom: 20px;
z-index: 999999;
}
#arrow span{
height: 20px;
width: 20px;
background-color: black;
color: #ffffff;
line-height: 20px;
text-align: center;
float: left;
margin-right: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="container">
<div id="content">
<div style="background-color: cornflowerblue"></div>
<div style="background-color: #999999"></div>
<div style="background-color: #CCCCCC"></div>
<div style="background-color: cadetblue"></div>
</div>
<div id="tab">
<ul>
<li class="selected">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
<div id="arrow">
<span id="prev"><</span>
<span id="next">></span>
</div>
</div>
<script src="jslib.js"></script>
<script>
var oContent = document.getElementById('content');
var aDiv = oContent.getElementsByTagName('div');
var oTab = document.getElementById('tab');
var aLi = oTab.getElementsByTagName('li');
var oNext = document.getElementById('next');
var oPrev = document.getElementById('prev');
var newDiv = aDiv[0].cloneNode();
oContent.appendChild(newDiv);
oContent.style.width = aDiv.length * aDiv[0].offsetWidth +'px';
var iNow = 0;
var iZIndex = 4;
for(var i = 0; i<aLi.length;i++){
aLi[i].index = i;
aDiv[i].style.zIndex = aDiv.length - i;
console.log(aDiv[0].style.zIndex);
aLi[i].onclick =function() {
change(this.index);
iNow = this.index;
}
}
function change(index){
for(var i = 0 ; i<aLi.length;i++){
aLi[i].className = '';
}
// aLi[index].className ='selected';
// aDiv[index].style.zIndex = ++iZIndex;
// aDiv[index].style.opacity = 0;
// animate(aDiv[index],{opacity:100});
// console.log(aDiv[index].style.zIndex);
aLi[index== aDiv.length -1 ? 0:index].className = 'selected';
animate(oContent,{left:-aDiv[0].offsetWidth *index})
}
oNext.onclick = function(){
iNow++;
if(iNow ==aDiv.length){
oContent.style.left = 0;
iNow = 1;
}
change(iNow);
};
oPrev.onclick = function(){
iNow--;
if(iNow ==-1){
oContent.style.left = -(aDiv.length-1)*aDiv[0].offsetWidth + 'px';
iNow = aDiv.length-2;
}
change(iNow);
};//
</script>
</body>
</html>