-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
118 lines (101 loc) · 3.44 KB
/
test.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>Document</title>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
height: 100vh;
/* overflow: hidden; */
}
.center {
display: flex;
flex-direction: column; /* Stack videos vertically */
width: 100vw;
height: 100vh;
overflow-y: scroll; /* Allow vertical scrolling */
scroll-snap-type: y mandatory; /* Snap to each video */
position: relative;
}
.video {
flex: 0 0 100vh; /* Take full height of viewport */
width: 100vw;
scroll-snap-align: start;
position: relative;
}
.video:nth-child(1) {
background: rgb(198, 85, 85);
}
.video:nth-child(2) {
background: rgb(188, 164, 164);
}
.video:nth-child(3) {
background: rgb(85, 134, 198);
}
.video:nth-child(4) {
background: rgb(76, 219, 93);
}
.video.active {
border: 2px solid yellow; /* Add a border to indicate active video */
}
.direction {
position: fixed;
top: 10px;
left: 10px;
padding: 10px;
background-color: rgba(0, 0, 0, 0.7);
color: white;
font-size: 16px;
z-index: 1000;
}
</style>
</head>
<body>
<div class="center" id="center">
<div class="video" id="video1"></div>
<div class="video" id="video2"></div>
<div class="video" id="video3"></div>
<div class="video" id="video4"></div>
</div>
<div class="direction" id="direction"></div>
<script>
let prevScrollPos = 0;
const center = document.getElementById('center');
const videos = document.querySelectorAll('.video');
const directionDiv = document.getElementById('direction');
center.addEventListener('scroll', function() {
var atSnappingPoint = center.scrollTop % center.offsetHeight === 0;
var timeOut = atSnappingPoint ? 0 : 150; // Adjust timeout as needed
clearTimeout(center.scrollTimeout); // Clear previous timeout
center.scrollTimeout = setTimeout(function() {
// Using the timeOut to evaluate scrolling state
if (!timeOut) {
console.log('Center snapped!');
} else {
console.log('User stopped scrolling on Center.');
}
}, timeOut);
let currentScrollPos = center.scrollTop;
let direction = currentScrollPos > prevScrollPos ? 'down' : 'up';
prevScrollPos = currentScrollPos;
directionDiv.textContent = `Scroll Direction: ${direction}`;
// Find the currently active video
videos.forEach(video => {
const rect = video.getBoundingClientRect();
if (rect.top >= 0 && rect.bottom <= window.innerHeight) {
// Video is in view
video.classList.add('active');
} else {
video.classList.remove('active');
}
});
});
</script>
</body>
</html>