-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo-LazyDom.html
More file actions
301 lines (284 loc) · 9.96 KB
/
demo-LazyDom.html
File metadata and controls
301 lines (284 loc) · 9.96 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>LazyDom</title>
<link href="demo.css" rel="stylesheet">
<script src="jquery.js"></script>
<link href="dist/css/H.min.css" rel="stylesheet" type="text/css">
<script src="dist/js/H.min.js"></script>
<style type="text/css">
ul {
list-style: none;
}
.goods-list{
overflow: hidden;
}
.goods-list .item{
width: 182px;
height: 192px;
padding: 5px 3px 6px 3px;
float: left;
}
.goods-list .inner{
border: 1px solid #e2e2e2;
}
.goods-list .item img{
width: 180px;
height: 130px;
border: none;
}
.goods-list .item .cont{
height: 60px;
padding: 0 5px;
}
.goods-list .item .name{
height: 30px;
line-height: 30px;
font-size: 14px;
color: #333333;
}
.goods-list .item .desc{
height: 25px;
line-height: 25px;
font-size: 12px;
color: #999999;
}
</style>
</head>
<body>
<div class="container">
<h2>LazyDom</h2>
<ul>
<li>使用方法请看源代码及注释</li>
</ul>
<div style="height: 50px"></div>
<h2>Demo</h2>
<ul id="J-wrap-1" class="goods-list"></ul>
<br>
<ul id="J-wrap-2" class="goods-list"></ul>
<br><br><br>
<div style="height: 100px;"></div>
<script type="text/html" id="J-tpl">
<li class="item">
<div class="inner">
<img class="lazy" data-original="<%= img %>" width="180" height="130">
<div class="cont">
<p class="name"><%= name %></p>
<p class="desc"><%= desc %></p>
</div>
</div>
</li>
</script>
</div>
<script type="text/javascript">
/*
* lazyDomData 数据格式说明:
* $node --- 需要插入 dom 元素的节点对象
* listItemHeight --- 商品列表每个商品元素的高度
* goodsCountPerRow --- 每行的商品数
* template --- 商品的渲染模版
* data --- 异步加载需要用到的商品数据
* renderCb --- 当前模块每次异步渲染完后执行的回调函数
* */
var lazyDomData = [{
$node: $('#J-wrap-1'),
listItemHeight: 200,
goodsCountPerRow: 5,
template: $('#J-tpl').html(),
data: [{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
}],
renderCb: function ($node, $createEl) {}
},{
$node: $('#J-wrap-2'),
listItemHeight: 200,
goodsCountPerRow: 5,
template: $('#J-tpl').html(),
data: [{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
},{
img: 'https://unsplash.it/g/180/130?image=0',
name: '商品1',
desc: '这里是商品1的商品概述'
}],
renderCb: function ($node, $createEl) {}
}];
/*
* lazyDom对象构造方法
*
* 参数说明:
* opts 【Obj】
* opts 对象的子属性:
* $target 【Jquery Dom Obj】 必传,绑定延迟加载触发滚动事件的目标对象,默认为 window,通常情况下不需要修改
* method 【String】 加载方式,默认是 fromToBottom 从下方异步插入 dom 结构,通常情况下不需要修改,传参可选值:fromToTop、fromToBottom
* distanceToPageBottom 【Number】 距离页面底部多少距离的时候触发加载,默认是 200,当 method 为 fromToBottom 时才生效
* isLazyLoad 【Boolean】 是否对延迟加载内容的图片做 lazyLoad 处理(前提是已经引入了 lazyLoad 插件,H.Util 默认自带),默认为 true
* lazyLoadThreshold 【Integer】 控制图片在它出现可视区域前多少像素时开始加载,当 isLazyLoad 为 true 时生效,默认为400
* allData 【Array】 延迟加载
* preRender 【Integer】 预加载的屏数
* renderCb 【Function】 延迟插入的 dom 结构渲染完成后执行的回调函数
* */
var lazyDom = new H.LazyDom({
distanceToPageBottom: 200,
isLazyLoad: true,
lazyLoadThreshold: 400,
allData: lazyDomData,
preRender: 1,
renderCb: function () {}
});
</script>
</body>
</html>