forked from xiangshuo1992/preload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
91 lines (86 loc) · 3.27 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图片预加载</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<style>
html,body {width: 100%;}
.box {text-align: center;}
a {display: inline-block;height: 30px;line-height: 30px;border: 1px solid #ccc;background-color: #fff;padding: 0 10px;margin-right: 50px;}
a:hover {background-color: #aaaaaa;}
.loading {position: fixed;top: 0;left: 0;width: 100%;height: 100%;text-align: center;font-size: 30px;background-color: #fff;}
.xl-progress-wp{position: absolute;width: 300px;height: 100px;top: 50%;left: 50%;margin: -50px 0 0 -150px;}
.xl-progress {position: relative;width: 100%;height: 16px;border-radius: 20px;background-color: #eeeeed;overflow: hidden;}
.xl-progress__inner {position: absolute;top: 0;left: 0;height: 100%;border-radius: 20px;background-color: #f3d08c;}
.xl-progress__txt {color: #959595;margin-top: 7px;text-align: center;}
</style>
</head>
<body>
<div class="box">
<img src="img/brief_1.jpg" alt="pic" id="img" style="width: 720px;height:400px;">
<p>
<a href="javascript:;" class="btn" data-controller="prev">上一页</a>
<a href="javascript:;" class="btn" data-controller="next">下一页</a>
</p>
</div>
<div class="loading">
<div class="xl-progress-wp">
<div class="xl-progress">
<i class="xl-progress__inner" style="width:0%;"></i>
</div>
<div class="xl-progress__txt">0%</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="js/preload.js"></script>
<script>
var imgs = [
'img/brief_1.jpg',
'img/brief_2.jpg',
'img/brief_3.jpg',
'img/brief_4.jpg',
'img/brief_5.jpg',
'img/brief_6.jpg',
'img/brief_7.jpg',
'img/brief_8.jpg',
'img/brief_9.jpg',
'img/brief_10.jpg',
'img/brief_11.jpg'
];
var index = 0,
len = imgs.length,
progressInner = $(".xl-progress__inner"),
progressTxt = $('.xl-progress__txt');
//图片预加载
$.preload(imgs, {
// 是否有序加载
order: false,
minTimer: 3000,
//每加载完一张执行的方法
each: function (count) {
var percent = Math.round((count+1) / len * 100) + '%';
progressInner.css("width",percent);
progressTxt.html(percent);
},
// 加载完所有的图片执行的方法
end: function () {
$('.loading').hide();
document.title = (index + 1) + '/' + len;
}
});
//按钮
$('.btn').on('click', function () {
if ($(this).data('controller') == 'prev') { //上一张
index = Math.max(0, --index);
} else { //下一张
index = Math.min(len - 1, ++index);
}
console.log($(this).data('controller'));
document.title = (index + 1) + '/' + len;
$('#img').attr('src', imgs[index]);
});
</script>
</body>
</html>