-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
127 lines (108 loc) · 4.16 KB
/
script.js
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
// let video = document.querySelector('video');
// playpause()
// // video.addEventListener("click",playpause);
// let captiontext = document.querySelector(".captiontext");
// let fullcaption = captiontext.innerText;
// let halfcaption = captiontext.innerText.substring(0,100)+"....";
// captiontext.innerText = halfcaption;
// captiontext.addEventListener("click",function(){
// if(fullcaption != captiontext.innerText){
// captiontext.innerText = fullcaption;
// } else {
// captiontext.innerText = halfcaption;
// }
// });
// video.addEventListener("ended", () => {changevideo()});
// let changevideo = (e) =>{
// console.log(e);
// document.getElementById("vid2").style.transform = "translateY(-100%)";
// Function to get URL parameter by name
function getUrlParameter(name) {
name = name.replace(/[\[\]]/g, '\\$&');
let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
let results = regex.exec(window.location.href);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
// Function to set URL parameter
function setUrlParameter(key, value) {
let url = new URL(window.location.href);
url.searchParams.set(key, value);
window.history.replaceState(null, null, url);
}
// }
let playpause = (video) => {
// console.log(video);
video.paused ? video.play() : video.pause();
video.parentElement.parentElement.querySelector(".playbtn").style.opacity =
video.paused ? 1 : 0;
// video.parentElement.parentElement.querySelector('.playbtn').style.scale = (video.paused)?1:.9;
};
// document.querySelectorAll("video").forEach((video) => {
// video.addEventListener("click", (e) => {
// playpause(e.target);
// // window.video = e.target;
// });
// });
// document.querySelectorAll("video").forEach((video) => {
// video.addEventListener("loadedmetadata", (e) => {
// // playpause(e.target);
// // window.video = e.target;
// });
// });
// document.querySelector(".wrapper").addEventListener("scroll", (e) => {
// // Check if the element being scrolled is the video element
// // if (e.target.tagName.toLowerCase() === 'video') {
// // // Do something with the scrolled video element
// // console.log(`Video with ID ${e.target.id} is being scrolled`);
// // }
// console.log(e.target);
// });
// document.addEventListener('scroll',(e)=>console.log(e.target));
let init = () => {
let prevScrollPos = 0;
const center = document.querySelector(".center");
const videos = document.querySelectorAll("video");
console.log(videos);
// const directionDiv = document.getElementById('direction');
center.addEventListener("scroll", function () {
document.querySelector(".active video").play();
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!");
// integrate()
} else {
integrate2()
console.log("User stopped scrolling on Center.");
}
}, timeOut);
let currentScrollPos = center.scrollTop;
let direction = currentScrollPos > prevScrollPos ? "down" : "up";
prevScrollPos = currentScrollPos;
let i = `Scroll Direction: ${direction}`;
console.log(i);
// Find the currently active video
videos.forEach((video, index) => {
const rect = video.getBoundingClientRect();
const isFullyVisible = rect.top >= 0 && rect.bottom <= window.innerHeight;
if (isFullyVisible) {
// Video is fully in view
video.classList.add("active");
document.body.style.background = "url("+video.dataset.poster+")";
document.body.style.backgroundRepeat = "no-repeat";
document.body.style.backgroundSize = "cover";
video.play();
setUrlParameter("id",video.getAttribute("id"));
} else {
// Video is not fully in view
video.classList.remove("active");
video.pause();
}
});
});
};