forked from verlok/vanilla-lazyload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamic_content_nodeset.html
193 lines (182 loc) · 7.54 KB
/
dynamic_content_nodeset.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
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8" />
<title>
Dynamic content passing nodeset - Lazyload demos
</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
ul,
li {
list-style-type: none;
margin: 0;
padding: 0;
}
a,
img {
display: block;
}
img {
border: 0;
width: 220px;
height: 280px;
}
img:not([src]) {
visibility: hidden;
}
button {
position: fixed;
bottom: 10px;
width: 10em;
height: 3em;
left: 50%;
margin-left: -5em;
}
</style>
</head>
<body>
<h1>Dynamic content passing nodeset demo</h1>
<button id="addContent">
ADD CONTENT
<span class="count"></span>
</button>
<div id="results1" class="results">
<ul>
<li>
<a href="#">
<img
alt="Stivaletti"
src="https://via.placeholder.com/440x560?text=Img+01"
width="220"
height="280"
/>
</a>
</li>
<li>
<a href="#">
<img
alt="Open toe"
src="https://via.placeholder.com/440x560?text=Img+02"
width="220"
height="280"
/>
</a>
</li>
<li>
<a href="#">
<img
alt="Sneakers & Tennis"
data-src="https://via.placeholder.com/440x560?text=Img+03"
width="220"
height="280"
/>
</a>
</li>
<li>
<a href="#">
<img
alt="Sneakers & Tennis shoes basse"
data-src="https://via.placeholder.com/440x560?text=Img+04"
width="220"
height="280"
/>
</a>
</li>
<li>
<a href="#">
<img
alt="Sneakers & Tennis shoes alte"
data-src="https://via.placeholder.com/440x560?text=Img+05"
width="220"
height="280"
/>
</a>
</li>
<li>
<a href="#">
<img
alt="Sneakers & Tennis shoes alte"
data-src="https://via.placeholder.com/440x560?text=Img+06"
width="220"
height="280"
/>
</a>
</li>
<li>
<a href="#">
<img
alt="Sneakers & Tennis shoes basse"
data-src="https://via.placeholder.com/440x560?text=Img+07"
width="220"
height="280"
/>
</a>
</li>
</ul>
</div>
<script src="../dist/lazyload.min.js"></script>
<script>
(function () {
var count = 0,
addContentButton,
additionalContent,
target;
function logElementEvent(eventName, element) {
console.log(Date.now(), eventName, element.getAttribute("data-src"));
}
var callback_enter = function (element) {
logElementEvent("🔑 ENTERED", element);
};
var callback_exit = function (element) {
logElementEvent("🚪 EXITED", element);
};
var callback_loading = function (element) {
logElementEvent("⌚ LOADING", element);
};
var callback_loaded = function (element) {
logElementEvent("👍 LOADED", element);
};
var callback_error = function (element) {
logElementEvent("💀 ERROR", element);
element.src =
"https://via.placeholder.com/440x560/?text=Error+Placeholder";
};
var callback_finish = function () {
logElementEvent("✔️ FINISHED", document.documentElement);
};
var callback_cancel = function (element) {
logElementEvent("🔥 CANCEL", element);
};
ll = new LazyLoad(
{
// Assign the callbacks defined above
callback_enter: callback_enter,
callback_exit: callback_exit,
callback_cancel: callback_cancel,
callback_loading: callback_loading,
callback_loaded: callback_loaded,
callback_error: callback_error,
callback_finish: callback_finish
},
document.querySelectorAll("img")
);
additionalContent = [
'<li><a href="#"><img alt="Sneakers & Tennis shoes basse" src="https://via.placeholder.com/440x560?text=Img+08" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Stivali" data-src="https://via.placeholder.com/440x560?text=Img+09" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Stivali" data-src="https://via.placeholder.com/440x560?text=Img+10" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Stivaletti" data-src="https://via.placeholder.com/440x560?text=Img+11" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Stivaletti" data-src="https://via.placeholder.com/440x560?text=Img+12" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Stivali" data-src="https://via.placeholder.com/440x560?text=Img+13" width="220" height="280"></a> </li>',
'<li><a href="#"><img alt="Stivaletti" src="https://via.placeholder.com/440x560?text=Img+14" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Décolleté" data-src="https://via.placeholder.com/440x560?text=Img+15" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Mocassini" data-src="https://via.placeholder.com/440x560?text=Img+16" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Stivaletti" data-src="https://via.placeholder.com/440x560?text=Img+17" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Décolleté" data-src="https://via.placeholder.com/440x560?text=Img+18" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Décolleté" data-src="https://via.placeholder.com/440x560?text=Img+19" width="220" height="280"></a> </li>',
'<li><a href="#"><img alt="Francesine" src="https://via.placeholder.com/440x560?text=Img+20" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Stivaletti" data-src="https://via.placeholder.com/440x560?text=Img+21" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Décolleté" data-src="https://via.placeholder.com/440x560?text=Img+22" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Mocassini" data-src="https://via.placeholder.com/440x560?text=Img+23" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Mocassini" data-src="https://via.placeholder.com/440x560?text=Img+24" width="220" height="280"></a> </li> <li> <a href="#"><img class="lazy" alt="Stivali" data-src="https://via.placeholder.com/440x560?text=Img+25" width="220" height="280"></a> </li>'
];
addContentButton = document.getElementById("addContent");
target = document.querySelector("#results1 ul");
addContentButton.addEventListener("click", function () {
if (count === additionalContent.length) {
return;
}
target.innerHTML += additionalContent[count];
ll.update(document.querySelectorAll(".lazy"));
addContentButton.disabled = ++count >= additionalContent.length;
});
})();
</script>
</body>
</html>