-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·118 lines (110 loc) · 4.22 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Video Layers</title>
<style>
body {
margin: 0;
overflow: hidden;
}
#container {
position: relative;
width: 100vw;
height: 100vh;
background-color: black;
}
video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
#video2 {
display: none; /* Initially hidden */
}
</style>
</head>
<body>
<!-- <div id="container" tabindex="0">
<video id="video1" width="100%" height="auto" controls preload="auto">
<source src="video1.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<video id="video2" width="100%" height="auto" controls preload="auto">
<source src="video2.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div> -->
<div id="container" tabindex="0">
<video id="video1" width="100%" height="auto" controls autoplay>
<source src="https://emagegroup-my.sharepoint.com/personal/lynx_thoi_emagegroup_com/Documents/Video-Switch/video1.mp4" type="video/mp4">
</video>
<video id="video2" width="100%" height="auto" controls autoplay>
<source src="https://emagegroup-my.sharepoint.com/personal/lynx_thoi_emagegroup_com/Documents/Video-Switch/video2.mp4" type="video/mp4">
</video>
</div>
<script>
const container = document.getElementById('container');
const video1 = document.getElementById('video1');
const video2 = document.getElementById('video2');
let isLayer1Visible = true;
// Function to toggle videos
function toggleVideos() {
if (isLayer1Visible) {
// Switch to Layer 2
video2.play();
video2.currentTime = video1.currentTime; // Sync playback position
video2.style.display = 'block';
video1.style.display = 'none';
} else {
// Switch to Layer 1
video1.play();
video1.currentTime = video2.currentTime; // Sync playback position
video1.style.display = 'block';
video2.style.display = 'none';
}
isLayer1Visible = !isLayer1Visible;
}
// Event listener for the spacebar
document.addEventListener('keydown', (event) => {
if (event.key === 'l') { // L key
event.preventDefault(); // Prevent default spacebar behavior (scrolling)
console.log("press L");
toggleVideos();
}
});
// Fullscreen function
function goFullScreen() {
if (container.requestFullscreen) {
container.requestFullscreen();
} else if (container.mozRequestFullScreen) { // Firefox
container.mozRequestFullScreen();
} else if (container.webkitRequestFullscreen) { // Safari
container.webkitRequestFullscreen();
} else if (container.msRequestFullscreen) { // IE/Edge
container.msRequestFullscreen();
}
}
// Optional: Trigger fullscreen on double-click anywhere in the container
container.addEventListener('dblclick', goFullScreen);
// Wait until both videos are ready before playing
let videosLoaded = 0;
function checkVideosLoaded() {
videosLoaded++;
if (videosLoaded === 2) {
console.log("Both videos are loaded and ready to play");
// Enable the video controls after both are ready
video1.play();
video2.play();
}
}
// Event listener for when both videos can start playing
video1.addEventListener('canplaythrough', checkVideosLoaded);
video2.addEventListener('canplaythrough', checkVideosLoaded);
</script>
</body>
</html>