-
Notifications
You must be signed in to change notification settings - Fork 10
/
DEMO.html
333 lines (275 loc) · 15.4 KB
/
DEMO.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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!--
* Vimeo LazyLoad
* v2.1.0
* https://github.com/the-muda-organization/vimeo-lazyload
* MIT License
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vimeo Lazyload</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
/* VARIABLES */
:root{
--vi-lazyload-logo-blue: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 109 31' fill='%231ab7ea'%3E%3Cpath d='M88.24 23.443a11.978 11.978 0 0 1-.054-.678c-.184-3.124.947-5.995 3.394-8.61 2.627-2.905 5.929-4.358 9.908-4.358 2.553 0 4.487.855 5.801 2.561 1.242 1.563 1.807 3.578 1.698 6.047-.147 3.342-1.387 6.23-3.723 8.663-2.335 2.434-5.237 3.65-8.704 3.65-2.882 0-5.072-.926-6.568-2.78a7.757 7.757 0 0 1-.871-1.372 34.1 34.1 0 0 1-1.235.727c-3.868 2.217-7.792 3.323-11.769 3.323-2.956 0-5.074-.982-6.35-2.945a7.353 7.353 0 0 1-.266-.422 21.55 21.55 0 0 1-.117.103c-2.446 2.108-4.89 3.162-7.335 3.162-2.374 0-3.522-1.307-3.45-3.926.036-1.164.265-2.562.684-4.198.42-1.636.648-2.909.685-3.818.037-1.38-.384-2.073-1.264-2.073-.952 0-2.086 1.13-3.404 3.384-1.392 2.365-2.144 4.656-2.252 6.874-.074 1.566.08 2.767.46 3.603-2.546.073-4.33-.346-5.348-1.256-.911-.8-1.33-2.126-1.255-3.983a14.67 14.67 0 0 1 .537-3.492c.321-1.164.5-2.2.537-3.11.074-1.347-.42-2.02-1.48-2.02-.915 0-1.902 1.038-2.96 3.111-1.06 2.073-1.645 4.239-1.754 6.494-.073 2.037.058 3.455.392 4.256-2.505.073-4.284-.454-5.337-1.58-.48-.518-.817-1.185-1.01-2.002-.205.194-.415.386-.631.574-2.446 2.108-4.89 3.162-7.335 3.162-1.133 0-2-.363-2.601-1.09-.602-.728-.885-1.672-.848-2.836.035-1.199.41-3.053 1.121-5.562.712-2.508 1.069-3.854 1.069-4.036 0-.944-.33-1.417-.985-1.417-.207 0-.77.34-1.69 1.016-.693 2.067-2.205 4.595-4.535 7.584-3.315 4.295-6.119 6.443-8.413 6.443-1.42 0-2.624-1.307-3.606-3.924L5.41 19.497c-.73-2.615-1.512-3.924-2.349-3.924-.182 0-.82.383-1.913 1.145L0 15.244a309.082 309.082 0 0 0 3.558-3.163c1.604-1.383 2.809-2.11 3.612-2.183 1.897-.182 3.065 1.111 3.503 3.88.474 2.986.802 4.844.986 5.57.547 2.479 1.148 3.716 1.806 3.716.51 0 1.276-.803 2.298-2.41 1.021-1.608 1.568-2.831 1.642-3.672.146-1.387-.401-2.082-1.642-2.082-.583 0-1.185.134-1.804.399 1.198-3.914 3.487-5.814 6.866-5.706 2.256.066 3.438 1.387 3.546 3.961L26 12.081c1.57-1.383 2.738-2.11 3.506-2.183 1.203-.109 2.088.244 2.654 1.06.564.816.774 1.875.63 3.18-.475 2.212-.987 5.02-1.534 8.425-.037 1.56.53 2.338 1.697 2.338.51 0 1.422-.537 2.737-1.615l.049-.04c.083-.76.218-1.662.405-2.708.3-1.687.468-3 .504-3.945.072-.652-.093-.979-.493-.979-.22 0-.84.369-1.862 1.104l-1.314-1.473c.183-.144 1.331-1.2 3.45-3.164 1.532-1.418 2.572-2.145 3.119-2.182.949-.073 1.715.318 2.299 1.172.584.855.876 1.847.876 2.974 0 .364-.036.71-.108 1.037a10.044 10.044 0 0 1 1.916-2.183c1.678-1.455 3.558-2.274 5.638-2.456 1.788-.145 3.064.273 3.833 1.255.619.8.91 1.947.875 3.438a73.7 73.7 0 0 0 .822-.71c.838-.982 1.659-1.763 2.462-2.345 1.35-.982 2.756-1.528 4.215-1.638 1.752-.145 3.01.271 3.777 1.25.656.798.949 1.94.877 3.424-.037 1.015-.284 2.492-.74 4.431-.457 1.94-.684 3.052-.684 3.342-.037.763.037 1.287.22 1.577.181.29.618.434 1.313.434.311 0 .773-.2 1.385-.602a9.877 9.877 0 0 1-.072-1.43c.035-2.945 1.35-5.745 3.942-8.401 2.845-2.909 6.203-4.365 10.072-4.365 3.576 0 5.474 1.453 5.693 4.355.145 1.85-.877 3.755-3.065 5.715-2.337 2.142-5.276 3.502-8.815 4.082.656.908 1.641 1.36 2.956 1.36 2.627 0 5.492-.664 8.596-1.997.138-.058.274-.117.408-.175zm14.56-5.244c.038-.984-.1-1.886-.41-2.706-.31-.82-.758-1.23-1.341-1.23-1.862 0-3.395 1.002-4.597 3.007-1.024 1.64-1.571 3.39-1.643 5.247-.037.912.128 1.714.492 2.406.4.803.966 1.203 1.697 1.203 1.642 0 3.048-.965 4.216-2.898.985-1.604 1.513-3.28 1.587-5.029zm-21.1-1.834c.035-.976-.365-1.465-1.203-1.465-1.094 0-2.204.751-3.334 2.253-1.13 1.502-1.713 2.94-1.748 4.315-.021 0-.021.236 0 .706a12.322 12.322 0 0 0 4.645-2.985c1.056-1.157 1.603-2.1 1.64-2.824zM34.651 2.714c-.036.906-.492 1.775-1.369 2.607-.985.941-2.153 1.412-3.503 1.412-2.08 0-3.084-.905-3.011-2.715.035-.94.592-1.846 1.669-2.715C29.513.435 30.708 0 32.023 0c.766 0 1.405.3 1.917.896.51.598.747 1.204.711 1.818z'/%3E%3C/svg%3E");
}
/* vimeo lazyload container */
.vi-lazyload{
width:100%;
position:relative!important;
overflow:hidden;
cursor:pointer;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
}
/* vimeo lazyload container ::before --> to maintain 16/9 ratio & black bg before JS loaded */
.vi-lazyload::before{
content:"";
width:100%;
display:block;
position:relative;
padding-top:56.25%; /*16:9 ratio*/
background-color:#000;
}
/* vimeo lazyload wrap */
.vi-lazyload-wrap{
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
padding:inherit;
}
/* vimeo lazyload content */
.vi-lazyload-content{
width:100%;
height:100%;
position:relative;
background-color:#000;
background-image:var(--vi-lazyload-img);
background-size:cover;
background-position:50%;
background-repeat:no-repeat;
}
/* play-btn */
.vi-lazyload-playbtn{
display:block;
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
z-index:1;
background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 13 8'%3E%3Crect fill='rgba(0,0,0,.65)' width='13' height='8' rx='1' ry='1'/%3E%3Cpolygon fill='%23fff' points='5 6 9 4 5 2'/%3E%3C/svg%3E");
background-position:50%;
background-size:calc(35px + 10%) auto;
background-repeat:no-repeat;
}
/* play-btn:hover */
.vi-lazyload-playbtn:hover{
background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 13 8'%3E%3Crect fill='%231ab7ea' width='13' height='8' rx='1' ry='1'/%3E%3Cpolygon fill='%23fff' points='5 6 9 4 5 2'/%3E%3C/svg%3E");
}
/* logo */
.vi-lazyload-logo{
display:block;
width:30%;
min-width:95px;
min-height:27px;
max-width:215px;
padding-top:8.6%; /* 28.440367% (logo height/width in %) * 0.3 (equivalent to width:30%) = 8.5321101% rounded up */
position:absolute;
right:4%;
bottom:4%;
z-index:2;
background-image:var(--vi-lazyload-logo-blue);
background-position:50%;
background-size:contain;
background-repeat:no-repeat;
opacity:.75;
transition:opacity .3s;
}
/* 0 = no logo! */
/* 1 = blue - #1ab7ea */.vi-lazyload[data-logo="1"] .vi-lazyload-logo{}
/* 2 = dark - #162221 */.vi-lazyload[data-logo="2"] .vi-lazyload-logo{filter:brightness(0) saturate(100%) invert(10%) sepia(31%) saturate(433%) hue-rotate(126deg) brightness(96%) contrast(95%)}
/* 3 = white - #fff */.vi-lazyload[data-logo="3"] .vi-lazyload-logo{filter:grayscale(100%) brightness(200%)}
/* logo:hover */
.vi-lazyload-logo:hover{
opacity:1;
transition:opacity .3s;
}
/* iframe */
.vi-lazyload iframe{
width:100%!important;
height:100%!important;
position:absolute;
top:0;
left:0;
z-index:3;
border:0;
background-color:#000;
}
</style>
</head>
<body class="bg-dark py-5">
<main class="container">
<!--SPACER TO TEST INTERSECTION OBSERVER API-->
<!--<section class="row" style="height:1000px"></section>-->
<section class="row row-cols-lg-2 row-cols-md-1 g-4 mb-5">
<article class="col">
<div class="vi-lazyload" data-id="272532681" data-thumb="" data-logo="2"></div>
</article>
<article class="col">
<div class="vi-lazyload img-thumbnail shadow" data-id="220550910" data-thumb="" data-logo="3"></div>
</article>
</section>
<section class="row row-cols-lg-3 row-cols-md-1 g-4 mb-5">
<article class="col">
<div class="vi-lazyload" data-id="271871608" data-thumb="" data-logo="3"></div>
</article>
<article class="col">
<div class="vi-lazyload" data-id="113641055" data-thumb="" data-logo="1"></div>
</article>
<article class="col">
<div class="vi-lazyload" data-id="64254961" data-thumb="" data-logo="2"></div>
</article>
</section>
<section class="row row-cols-lg-4 row-cols-md-2 row-cols-sm-1 g-4 mb-5">
<article class="col">
<div class="vi-lazyload" data-id="190667241" data-thumb="" data-logo="3"></div>
</article>
<article class="col">
<div class="vi-lazyload" data-id="271871608" data-thumb="" data-logo="3"></div>
</article>
<article class="col">
<div class="vi-lazyload" data-id="220550910" data-thumb="" data-logo="3"></div>
</article>
<article class="col">
<div class="vi-lazyload" data-id="190667241" data-thumb="" data-logo="3"></div>
</article>
</section>
<section class="row row-cols-lg-4 row-cols-md-2 row-cols-sm-1 g-4 mb-5">
<article class="col">
<div class="card w-100 bg-light">
<div class="card-header">2020-06-20</div>
<div class="vi-lazyload" data-id="271871608" data-thumb="" data-logo="3"></div>
<div class="card-footer h5 m-0">Lorem Ipsum Dolor</div>
</div>
</article>
<article class="col">
<div class="card w-100 bg-light">
<div class="vi-lazyload card-img-top" data-id="272532681" data-thumb="" data-logo="2"></div>
<div class="card-footer h5 m-0">Lorem Ipsum</div>
</div>
</article>
<article class="col">
<div class="vi-lazyload img-thumbnail shadow" data-id="64254961" data-thumb="" data-logo="2"></div>
</article>
<article class="col">
<div class="vi-lazyload img-thumbnail shadow" data-id="271871608" data-thumb="" data-logo="0"></div>
</article>
</section>
</main>
<script>
(function(){
/*
* IDEAS FOR THE FUTURE:
* - Add data-title attribute to add overlay with title [optional]
* -
*/
/********************************************************************
************************** MAIN VARIABLES ***************************
*********************************************************************/
var vimeo = document.querySelectorAll('.vi-lazyload'),
vimeo_observer, //Intersection Observer API
template_wrap,
template_content,
template_playbtn,
template_logo,
template_iframe,
settings_observer_rootMargin = '200px 0px', //Intersection Observer API option - rootMargin (Y, X)
settings_thumb_base_url = 'https://raw.githubusercontent.com/the-muda-organization/vimeo-lazyload/master/demo-img/', //Base URL where thumbnails are stored
settings_thumb_extension = 'webp'; //Thumbnail extension
/********************************************************************
************************ IF ELEMENTS EXIST **************************
*********************************************************************/
if(vimeo.length > 0){
//create elements
template_wrap = document.createElement('div');
template_content = document.createElement('div');
template_playbtn = document.createElement('div');
template_logo = document.createElement('a');
template_iframe = document.createElement('iframe');
//set attributes
template_wrap.classList.add('vi-lazyload-wrap');
template_content.classList.add('vi-lazyload-content');
template_playbtn.classList.add('vi-lazyload-playbtn');
template_logo.classList.add('vi-lazyload-logo');
template_logo.target = '_blank';
template_logo.rel = 'noreferrer';
template_iframe.setAttribute('allow','autoplay;fullscreen;picture-in-picture');
template_iframe.setAttribute('allowfullscreen','');
/********************************************************************
********************* INTERSECTION OBSERVER API *********************
*********************************************************************/
vimeo_observer = new IntersectionObserver(function(elements){
elements.forEach(function(e){
//VARIABLES
var this_element = e.target,
this_wrap,
this_content,
this_playbtn,
this_logo,
this_iframe,
this_data_id = e.target.dataset.id,
this_data_thumb = e.target.dataset.thumb,
this_data_logo = e.target.dataset.logo;
//if element appears in viewport
if(e.isIntersecting === true){
//wrap
this_wrap = template_wrap.cloneNode();
this_element.append(this_wrap);
//content
this_content = template_content.cloneNode();
this_wrap.append(this_content);
//background-image
this_content.style.setProperty('--vi-lazyload-img','url("' + settings_thumb_base_url + this_data_id + this_data_thumb + '.' + settings_thumb_extension + '")');
//play btn
this_playbtn = template_playbtn.cloneNode();
this_content.append(this_playbtn);
//logo link
if(this_data_logo !== '0'){
this_logo = template_logo.cloneNode();
this_logo.href = 'https://vimeo.com/' + this_data_id;
this_content.append(this_logo);
}
//onclick create iframe
this_playbtn.addEventListener('click',function(){
this_iframe = template_iframe.cloneNode();
this_iframe.src = 'https://player.vimeo.com/video/' + this_data_id + '?autoplay=1&autopause=0';
this_content.append(this_iframe);
});
//Unobserve after image lazyloaded
vimeo_observer.unobserve(this_element);
//LOG
//console.log('DONE - ' + this_data_id);
}
});
},{
rootMargin: settings_observer_rootMargin,
});
/********************************************************************
********************* ITERATE THROUGH ELEMENTS **********************
*********************************************************************/
vimeo.forEach(function(e){
//Intersection Observer API - observe elements
vimeo_observer.observe(e);
});
}
})();
</script>
</body>
</html>