-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
96 lines (96 loc) · 2.26 KB
/
index.html
File metadata and controls
96 lines (96 loc) · 2.26 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图片预加载之无序加载</title>
<style>
html,body{
width: 100%;
height: 100%;
}
a{
text-decoration: none;
}
.box{
text-align: center;
}
.btn{
display: inline-block;
height: 30px;
line-height: 30px;
border:1px solid #ccc;
background-color:#fff;
padding:0 10px;
margin-right: 50px;
color:#333;
}
.btn:hover{
background: #eee;
}
img{
width: 300px;
height: 200px;
}
.loading{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #eeeeee;
text-align: center;
font-size: 30px;
}
.progress{
margin-top: 30px;
}
</style>
</head>
<body>
<div class="box">
<img src="images/1.jpg" alt="" id="img">
<p>
<a href="javascript:" class="btn" data-control="prev">上一页</a>
<a href="javascript:" class="btn" data-control="next">下一页</a>
</p>
</div>
<div class="loading">
<p class="progress">0%</p>
</div>
<script src="js/jquery-3.3.1.js"></script>
<script src="js/preload.js"></script>
<script>
var imgs = [
"images/1.jpg",
"images/2.jpg",
"images/3.jpg",
"images/4.jpg",
"images/5.jpg",
"images/6.jpg",
"images/7.jpg"
],
index = 0,
len = imgs.length,
$progress = $(".progress");
$.preload(imgs,{
each:function (count) {
$progress.html(Math.round((count + 1)/len * 100) + "%");
},
all:function () {
$(".loading").hide();
document.title = "1/"+len;
}
});
$(".btn").click(function () {
if($(this).data("control") === "prev"){
//上一张
index = Math.max(0,--index);
}else {
index = Math.min(len - 1,++index)
}
document.title = (index + 1) + "/" + len;
$("#img").attr("src",imgs[index]);
})
</script>
</body>
</html>