-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
156 lines (156 loc) · 4.11 KB
/
index.html
File metadata and controls
156 lines (156 loc) · 4.11 KB
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
155
156
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
overflow: hidden;
}
#box{
width: 375px;
height: 600px;
border: 10px solid #000;
margin: 0 auto;
overflow: hidden;
position: relative;
}
ul{
width: 5000px;
height: 600px;
overflow: hidden;
position: absolute;
}
ul li{
width: 375px;
height: 600px;
float: left;
}
ul li img{
width: 100%;
height: 100%;
}
.left,.right{
width: 30px;
height: 60px;
text-align: center;
font: 30px/2 simsun;
color: white;
background: rgba(0,0,0,.5);
position: absolute;
z-index: 10;
top: 50%;
margin-top: -30px;
}
.left{
left: 10px;
cursor:pointer;
}
.right{
right: 10px;
cursor:pointer;
}
.disc{
position: absolute;
z-index: 10;
bottom: 10px;
left: 0;
right: 0;
height: 40px;
text-align: center;
}
.disc span{
display: inline-block;
width: 20px;
height: 20px;
border-radius: 50%;
background: gray;
margin: 5px;
}
.disc .active{
background: red;
}
</style>
</head>
<body>
<div id="box">
<ul></ul>
<div class="left"><</div>
<div class="right">></div>
<div class="disc">
</div>
</div>
</body>
</html>
<script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
var i = 0;
function getImg(){
$.ajax({
type:"get",
url:"http://gank.io/api/data/%E7%A6%8F%E5%88%A9/10/1",
async:true,
success:function(res){
// console.log(res.results)
var data = res.results;
var html = "";
$.each(data, function(i,val) {
html += '<li><img src="'+ val.url +'" alt="'+ i +'" /></li>';
$(".disc").append("<span/>")
});
html += '<li><img src="'+ data[0].url +'" alt="1" /></li>';
$(".disc span").eq(0).addClass("active");
$("ul").prepend(html);
// console.log(html)
}
});
}
var w = $("#box").width();
function change(){
var length = $("#box li").size();
i++;
if (i == length) {
$('ul').css({left:0});
i = 1;
}
if (i==length-1) {
$(".disc span").eq(0).addClass("active")
.siblings().removeClass("active")
}
$(".disc span").eq(i).addClass("active")
.siblings().removeClass("active");
$('ul').stop().animate({left:-w*i})
}
getImg();
$("#box").on("click",".right",function(){
change();
});
$("#box").on("click",".left",function(){
var length = $("#box li").size();
i--;
console.log(length,i);
if (i == -1) {
i = length-2;
$('ul').css({left:-w*(length-1)})
}
$('ul').stop().animate({left:-w*i});
$(".disc span").eq(i).addClass("active")
.siblings().removeClass("active")
});
$(".disc").on("click","span",function(){
i = $(this).index() -1;
change();
});
var timer = setInterval(change,2000);
$("#box").hover(function(){
clearInterval(timer);
},function(){
timer = setInterval(change,2000);
})
</script>