-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathindex.jquery.html
65 lines (57 loc) · 1.64 KB
/
index.jquery.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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<title>图片预加载之无序加载-juqery实现</title>
<link rel=stylesheet href="css/preload.css">
</head>
<body>
<div class="box">
<img id="img" src="images/timg2.jpg" alt="pic">
<p>
<a href="javascript:;" class="btn" data-control='prev'>上一张</a>
<a href="javascript:;" class="btn" data-control='next'>下一张</a>
</p>
</div>
<!-- loading -->
<div class="loading">
<p class="progress">0%</p>
</div>
</body>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/preload.jquery.js"></script>
<script>
var imgs = [
'images/img1.jpg',
'images/img2.jpeg',
'images/img3.jpg',
'images/img4.jpg',
'images/timg.jpg',
'images/timg2.jpg',
'images/360wallpaper.jpg'
];
var 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').on('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>
</html>