forked from sl1673495/easy-lazyload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (119 loc) · 2.86 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="referrer" content="no-referrer" />
<title>easy-lazyload</title>
<style>
* {
margin: 0;
padding: 0;
}
.introduce {
padding: 10px 0;
text-align: center;
}
.github {
line-height: 25px;
text-align: center;
}
.github a {
text-decoration: none;
color: #37a;
}
.img-wrap {
font-size: 0;
}
.loading {
padding: 10px;
text-align: center;
font-weight: 700;
font-size: 14px;
color: #999
}
img {
box-sizing: border-box;
padding: 5px;
display: inline-block;
width: 100%;
min-height: 300px;
border: 0;
}
</style>
</head>
<body>
<div class="content">
<h1 class="introduce">
easy-lazyload
</h1>
<p class="github">
<a href="https://github.com/sl1673495/easy-lazyload">github地址</a>
</p>
<div class="img-wrap"></div>
</div>
<script src="./sisters.js"></script>
<script src='./assets/images/loading.js'></script>
<script src="./easy-lazyload.js"></script>
<script>
var pageNum = 1
var loader
// 插入图片节点
appendSisters()
// 插入底部瀑布流占位节点
appenLoading()
// 初始化懒加载
initLoader()
// 初始化瀑布流
initLoadMore()
function appendSisters() {
var sisters = getSisters(pageNum)
if (!sisters.length) {
return false
}
var warp = document.querySelector('.img-wrap')
for (var i = 0; i < sisters.length; i++) {
var img = document.createElement('img')
img.setAttribute('data-src', sisters[i])
warp.appendChild(img)
}
pageNum ++
return true
}
function appenLoading() {
var loading = document.createElement('div')
loading.classList.add('loading')
loading.innerText = '正在加载中...'
document.querySelector('.content').appendChild(loading)
}
function initLoader() {
loader = new EasyLazyLoad('.img-wrap', {
preLoad: 1,
loading: LOADING_URL,
error: LOADING_URL,
beforeMount: function (img) {
img.style.opacity = 0
},
mounted: function (img) {
img.style.transition = 'all .8s'
img.style.opacity = 1
}
})
}
function initLoadMore() {
var loadMore = new EasyLazyLoad('.loading', {
onLoadMore: function (done) {
var hasMore = appendSisters()
if (hasMore) {
loader.refresh()
done()
}else {
document.querySelector('.loading').innerText = '没有更多了'
}
}
})
}
</script>
</body>
</html>