-
Notifications
You must be signed in to change notification settings - Fork 54
/
index.html
executable file
·374 lines (321 loc) · 20.3 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
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>📺 Youtube Background</title>
<meta name="description" content="Simple script for embedding YouTube videos as cover background">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Lato:400,700&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/228006f19a.js" crossorigin="anonymous"></script>
<link href="style.css" rel="stylesheet">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery.youtube-background.js?v=1.1.2"></script>
<script type="text/javascript" src="youtube-background-experimental.js?v=1.1.2"></script>
</head>
<body>
<div class="container">
<main>
<div id="vbg-group-1" class="example-marquee vbg-group js-vbg-group">
<div id="vbg12" data-vbg-loop="false" data-vbg="https://www.youtube.com/watch?v=LC5rEhxGqT4" data-vbg-poster="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg"></div>
<div id="vbg13" data-vbg-autoplay="false" data-vbg-loop="false" style="display: none; position: absolute; width: 100%; height: 100%; top: 0; left: 0;" data-vbg="https://vimeo.com/137250145" data-vbg-poster="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg"></div>
<div id="vbg14" data-vbg-autoplay="false" data-vbg-loop="false" style="display: none; position: absolute; width: 100%; height: 100%; top: 0; left: 0;" data-vbg-start-at="10" data-vbg-end-at="60" data-vbg="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" data-vbg-poster="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg"></div>
<div class="content">
<div class="inner">
<h1>Group!</h1>
<button class="group-prev">Prev</button><button class="group-play">Play</button><button class="group-pause">Pause</button><button class="group-next">Next</button><br>
<button class="group-mute">Mute</button><button class="group-unmute">Unmute</button><br>
<button class="group-fullscreen">Fullscreen</button>
</div>
</div>
<div class="seek-bars" style="width: calc(100% - 24px); position: absolute; bottom: 16px; left: 12px; display: flex; flex-flow: row nowrap;">
<div data-target="#vbg12" class="seek-bar-wrapper js-seek-bar-wrap" style="width: 100%; margin: 0 4px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
<div data-target="#vbg13" class="seek-bar-wrapper js-seek-bar-wrap" style="width: 100%; margin: 0 4px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
<div data-target="#vbg14" class="seek-bar-wrapper js-seek-bar-wrap" style="width: 100%; margin: 0 4px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
<div class="example-marquee">
<div id="vbg" data-vbg-mobile="true" data-vbg-load-background="true" data-vbg="https://www.youtube.com/watch?v=eEpEeyqGlxA"></div>
<div class="content">
<div class="inner">
<h1>Cake in a frying pan? Impossible!</h1>
<button class="vbg-destroy" data-selector="#vbg">Destroy</button>
<button class="vbg-initialize" data-selector="#vbg" data-src="https://www.youtube.com/watch?v=LC5rEhxGqT4">Initialize</button>
<div data-target="#vbg" class="seek-bar-wrapper" style="width: calc(100% - 32px); position: absolute; bottom: 16px; left: 16px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
</div>
<div class="example-marquee">
<div id="vbg1" data-vbg-play-button="true" data-vbg-start-at="10" data-vbg-end-at="16" data-vbg="https://www.youtube.com/watch?v=MgDZBqTuUuE" data-vbg-load-background="true"></div>
<div class="content">
<div class="inner">
<h1>Click the button to pause.</h1>
<h2>P.S. it also starts 10s into the video to skip the video intro and ends 16s into the video for shorter loops</h2>
<div data-target="#vbg1" class="seek-bar-wrapper" style="width: calc(100% - 32px); position: absolute; bottom: 16px; left: 16px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
</div>
<div class="example-marquee">
<div id="vbg2" data-vbg-end-at="1.25" data-vbg-mute-button="true" data-vbg-play-button="true" data-vbg-resolution="4:3" data-vbg="https://www.youtube.com/watch?v=27mt_xpeZTw"></div>
<div class="content">
<div class="inner">
<h1>Mute / Unmute.</h1>
<button class="src-change-button" data-src="https://www.youtube.com/watch?v=UIyoNvInzCI">Change Source</button>
<div data-target="#vbg2" class="seek-bar-wrapper" style="width: calc(100% - 32px); position: absolute; bottom: 16px; left: 16px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
</div>
<div class="example-marquee">
<div id="vbg3" data-vbg-mute-button="true" data-vbg-play-button="true" data-vbg-resolution="4:3" data-vbg-volume="0.15" data-vbg="https://www.youtube.com/watch?v=DLzxrzFCyOs
"></div>
<div class="content">
<div class="inner">
<h1>Mute / Unmute.</h1>
<button class="toggle-play-button" data-target="#vbg3">Toggle Play</button>
<button class="toggle-mute-button" data-target="#vbg3">Toggle Mute</button>
<div data-target="#vbg3" class="seek-bar-wrapper" style="width: calc(100% - 32px); position: absolute; bottom: 16px; left: 16px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
</div>
<div class="example-marquee">
<div id="vbg4" data-vbg="https://vimeo.com/137250145" data-vbg-play-button="true" data-vbg-mute-button="true"></div>
<div class="content">
<div class="inner">
<h1>VIMEO!</h1>
<button class="src-change-button" data-src="https://vimeo.com/64289386">Change Source</button>
<div data-target="#vbg4" class="seek-bar-wrapper" style="width: calc(100% - 32px); position: absolute; bottom: 16px; left: 16px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
</div>
<div class="example-marquee">
<div id="vbg5" data-vbg-resolution="4:1" data-vbg="https://vimeo.com/101926580" data-vbg-play-button="true" data-vbg-mute-button="true" data-vbg-always-play="true" data-vbg-volume="0.15" data-vbg-load-background="true"></div>
<div class="content">
<div class="inner">
<h1>VIMEO!</h1>
<div data-target="#vbg5" class="seek-bar-wrapper" style="width: calc(100% - 32px); position: absolute; bottom: 16px; left: 16px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
</div>
<div class="example-marquee">
<div id="vbg9" data-vbg="https://vimeo.com/304887422/34c51f7a09" data-vbg-play-button="true" data-vbg-mute-button="true" data-vbg-always-play="true" data-vbg-volume="0.15" data-vbg-load-background="true"></div>
<div class="content">
<div class="inner">
<h1>VIMEO UNLISTED!</h1>
<div data-target="#vbg5" class="seek-bar-wrapper" style="width: calc(100% - 32px); position: absolute; bottom: 16px; left: 16px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
</div>
<div class="example-marquee">
<div id="vbg6" data-vbg="https://vimeo.com/1084537" data-vbg-start-at="10" data-vbg-end-at="60" data-vbg-play-button="true" data-vbg-mute-button="true" data-vbg-poster="https://i.imgur.com/9lF2ewQ.png"></div>
<div class="content">
<div class="inner">
<h1>VIMEO CONTROLS!</h1>
<div data-target="#vbg6" class="seek-bar-wrapper" style="width: calc(100% - 32px); position: absolute; bottom: 16px; left: 16px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
</div>
<div class="example-marquee">
<div id="vbg7" data-vbg="https://download.samplelib.com/mp4/sample-5s.mp4" data-vbg-play-button="true" data-vbg-mute-button="true"></div>
<div class="content">
<div class="inner">
<h1>HTML5 VIDEO!</h1>
<button class="src-change-button" data-src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4">Change Source</button>
<div data-target="#vbg7" class="seek-bar-wrapper" style="width: calc(100% - 32px); position: absolute; bottom: 16px; left: 16px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
</div>
<div class="example-marquee">
<div id="vbg8" data-vbg-start-at="10" data-vbg-end-at="60" data-vbg="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" data-vbg-poster="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg" data-vbg-play-button="true" data-vbg-mute-button="true"></div>
<div class="content">
<div class="inner">
<h1>HTML5 VIDEO!</h1>
<div data-target="#vbg8" class="seek-bar-wrapper" style="width: calc(100% - 32px); position: absolute; bottom: 16px; left: 16px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
</div>
<!--
<div class="example-marquee vbg-group">
<div id="vbg9" data-vbg-loop="false" data-vbg-start-at="10" data-vbg-end-at="60" data-vbg="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" data-vbg-poster="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg"></div>
<div id="vbg10" data-vbg-loop="false" style="display: none; position: absolute; width: 100%; height: 100%; top: 0; left: 0;" data-vbg="https://vimeo.com/137250145" data-vbg-poster="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg"></div>
<div id="vbg11" data-vbg-loop="false" style="display: none; position: absolute; width: 100%; height: 100%; top: 0; left: 0;" data-vbg="https://www.youtube.com/watch?v=LC5rEhxGqT4" data-vbg-poster="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg"></div>
<div class="content">
<div class="inner">
<h1>Group!</h1>
<button class="group-prev">Prev</button><button class="group-next">Next</button>
<div class="seek-bars" style="width: calc(100% - 24px); position: absolute; bottom: 16px; left: 12px; display: flex; flex-flow: row nowrap;">
<div data-target="#vbg9" class="seek-bar-wrapper js-seek-bar-wrap" style="width: 100%; margin: 0 4px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
<div data-target="#vbg10" class="seek-bar-wrapper js-seek-bar-wrap" style="width: 100%; margin: 0 4px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
<div data-target="#vbg11" class="seek-bar-wrapper js-seek-bar-wrap" style="width: 100%; margin: 0 4px;">
<progress class="seek-bar-progress js-seek-bar-progress" value="0" max="100" aria-hidden="true"></progress>
<input type="range" value="0" min="0" max="100" step="any" aria-label="Seek" class="seek-bar js-seek-bar">
</div>
</div>
</div>
</div>
</div>
-->
</main>
</div>
<script src="http://localhost:35729/livereload.js?snipver=1"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
const groupElements = document.querySelectorAll('.js-vbg-group');
for (let i = 0; i < groupElements.length; i++) {
const groupElement = groupElements[i];
const elements = groupElement.querySelectorAll('[data-vbg]');
for (let j = 0; j < elements.length; j++) {
elements[j].addEventListener('video-background-state-change', function(event) {
const id = event.target.getAttribute('id');
console.log(id, event.detail.type, event.detail.currentState);
});
elements[j].addEventListener('video-background-ready', function(event) {
const id = event.target.getAttribute('id');
console.log('ready', id, event.detail.type, event.detail.currentState);
});
}
}
jQuery('[data-vbg]').youtube_background();
const groups = new VideoBackgroundGroups(groupElements);
for (const i in groups.instances) {
const group = groups.instances[i].element;
const vbgroup = groups.instances[i];
const groupPrev = group.querySelector('.group-prev');
const groupNext = group.querySelector('.group-next');
const groupPlay = group.querySelector('.group-play');
const groupPause = group.querySelector('.group-pause');
const groupMute = group.querySelector('.group-mute');
const groupUnmute = group.querySelector('.group-unmute');
const groupFullscreen = group.querySelector('.group-fullscreen');
groupPrev.addEventListener('click', function() {
vbgroup.prev();
})
groupNext.addEventListener('click', function() {
vbgroup.next();
})
groupPlay.addEventListener('click', function() {
vbgroup.play();
})
groupPause.addEventListener('click', function() {
vbgroup.pause();
})
groupMute.addEventListener('click', function() {
vbgroup.mute();
})
groupUnmute.addEventListener('click', function() {
vbgroup.unmute();
})
groupFullscreen.addEventListener('click', function() {
console.log(vbgroup.currentElement.closest('.js-vbg-group'));
vbgroup.currentElement.closest('.js-vbg-group').webkitRequestFullscreen();
})
}
});
const vbgs = document.querySelectorAll('[data-vbg]');
//for (let i = 0; i < vbgs.length; i++) {
//vbgs[i].addEventListener('video-background-state-change', function(event) {
//const id = event.target.getAttribute('id');
//console.log(id, event.detail.type, event.detail.currentState);
//});
/*
vbgs[i].addEventListener('video-background-time-update', function(event) {
const id = event.target.getAttribute('id');
console.log(id, event.detail.type, event.detail.percentComplete);
});
*/
//}
const srcChangeButtons = document.querySelectorAll('.src-change-button');
for (let i = 0; i < srcChangeButtons.length; i++) {
srcChangeButtons[i].addEventListener('click', function(event) {
const target = event.target;
const src = target.getAttribute('data-src');
const vbgElem = target.closest('.example-marquee').querySelector('[data-vbg]');
if (!vbgElem) return;
const uid = vbgElem.getAttribute('data-vbg-uid');
if (!uid) return;
window.VIDEO_BACKGROUNDS.index[uid].setSource(src);
})
}
const destroyBtns = document.querySelectorAll('.vbg-destroy');
for (let i = 0; i < destroyBtns.length; i++) {
destroyBtns[i].addEventListener('click', function(event) {
const target = event.target;
const selector = target.getAttribute('data-selector');
const vbgElem = document.querySelector(selector);
window.VIDEO_BACKGROUNDS.destroy(vbgElem);
})
}
const initBtns = document.querySelectorAll('.vbg-initialize');
for (let i = 0; i < initBtns.length; i++) {
initBtns[i].addEventListener('click', function(event) {
const target = event.target;
const selector = target.getAttribute('data-selector');
const src = target.getAttribute('data-src');
const vbgElem = document.querySelector(selector);
if (!vbgElem) return;
if (vbgElem.getAttribute('data-vbg-uid')) window.VIDEO_BACKGROUNDS.destroy(vbgElem);
if (src) {
vbgElem.setAttribute('data-vbg', src);
}
window.VIDEO_BACKGROUNDS.add(vbgElem);
})
}
const seekInputs = document.querySelectorAll('.seek-bar-wrapper');
for (let i = 0; i < seekInputs.length; i++) {
new SeekBar(seekInputs[i]);
}
const playToggle = document.querySelectorAll('.toggle-play-button');
for (let i = 0; i < playToggle.length; i++) {
new PlayToggle(playToggle[i]);
}
const muteToggle = document.querySelectorAll('.toggle-mute-button');
for (let i = 0; i < muteToggle.length; i++) {
new MuteToggle(muteToggle[i]);
}
</script>
</body>
</html>