-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
272 lines (233 loc) · 6.64 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
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
console.clear();
/* Smooth Scroll */
const lenis = new Lenis()
function raf(time) {
lenis.raf(time)
requestAnimationFrame(raf)
}
requestAnimationFrame(raf)
/* Make sure the video is 'activated' on iOS */
function once(el, event, fn, opts) {
const onceFn = function (e) {
el.removeEventListener(event, onceFn);
fn.apply(this, arguments);
};
el.addEventListener(event, onceFn, opts);
return onceFn;
}
/* All Videos */
const mainvideo = document.querySelector(".main-video-background");
const secondaryvideo = document.querySelector(".secondary-video-background");
const video1 = document.querySelector(".video-background1");
const video2 = document.querySelector(".video-background2");
const video3 = document.querySelector(".video-background3");
once(document.documentElement, "touchstart", function (e) {
mainvideo.play();
mainvideo.pause();
secondaryvideo.play();
secondaryvideo.pause();
video1.play();
video1.pause();
video2.play();
video2.pause();
video3.play();
video3.pause();
});
/* Scroll Control! */
gsap.registerPlugin(ScrollTrigger);
ScrollTrigger.matchMedia({
/* Mobile View */
"(max-width: 768px)": function () {
/* Main Video */
let t4 = gsap.timeline({
defaults: { duration: 1 },
scrollTrigger: {
trigger: "#mainvideocontainer",
start: "top 28%",
end: "bottom 15%",
scrub: true
}
});
once(mainvideo, "loadedmetadata", () => {
t4.fromTo(
mainvideo,
{
currentTime: 0
},
{
currentTime: mainvideo.duration || 1
}
);
});
/* Secondary Video */
let t5 = gsap.timeline({
defaults: { duration: 1 },
scrollTrigger: {
trigger: "#secondaryvideocontainer",
start: "top 70%",
end: "bottom 25%",
scrub: true
}
});
once(secondaryvideo, "loadedmetadata", () => {
t5.fromTo(
secondaryvideo,
{
currentTime: 0
},
{
currentTime: secondaryvideo.duration || 1
}
);
});
},
/* Desktop View */
"(min-width: 769px)": function () {
/* Main Video */
let t4 = gsap.timeline({
defaults: { duration: 1 },
scrollTrigger: {
trigger: "#mainvideocontainer",
start: "top 35%",
end: "bottom 25%",
scrub: true
}
});
once(mainvideo, "loadedmetadata", () => {
t4.fromTo(
mainvideo,
{
currentTime: 0
},
{
currentTime: mainvideo.duration || 1
}
);
});
/* Secondary Video */
let t5 = gsap.timeline({
defaults: { duration: 1 },
scrollTrigger: {
trigger: "#secondaryvideocontainer",
start: "top 50%",
end: "bottom 40%",
scrub: true
}
});
once(secondaryvideo, "loadedmetadata", () => {
t5.fromTo(
secondaryvideo,
{
currentTime: 0
},
{
currentTime: secondaryvideo.duration || 1
}
);
});
}
});
/* Video 1 */
let tl = gsap.timeline({
defaults: { duration: 1 },
scrollTrigger: {
trigger: "#videocontainer1",
start: "top 70%",
end: "bottom 10%",
scrub: true
}
});
once(video1, "loadedmetadata", () => {
tl.fromTo(
video1,
{
currentTime: 0
},
{
currentTime: video1.duration || 1
}
);
});
/* Video 2 */
let t2 = gsap.timeline({
defaults: { duration: 1 },
scrollTrigger: {
trigger: "#videocontainer2",
start: "top 70%",
end: "bottom 10%",
scrub: true
}
});
once(video2, "loadedmetadata", () => {
t2.fromTo(
video2,
{
currentTime: 0
},
{
currentTime: video2.duration || 1
}
);
});
/* Video 3 */
let t3 = gsap.timeline({
defaults: { duration: 1 },
scrollTrigger: {
trigger: "#videocontainer3",
start: "top 70%",
end: "bottom 10%",
scrub: true,
}
});
once(video3, "loadedmetadata", () => {
t3.fromTo(
video3,
{
currentTime: 0
},
{
currentTime: video3.duration || 1
}
);
});
// Add this to your existing script.js file or in a <script> tag in the head of your HTML
document.addEventListener("DOMContentLoaded", function () {
const modal = document.getElementById("demoModal");
const btn = document.querySelector("#modal_btn");
const closeBtn = document.querySelector(".close");
const form = document.getElementById("demoForm");
const navBtn = document.getElementById("nav_btn");
navBtn.addEventListener("click", function () {
document.documentElement.style.scrollBehavior = "smooth";
});
window.onscroll = function () {
document.documentElement.style.scrollBehavior = "";
};
btn.addEventListener("click", function () {
modal.style.display = "block";
});
closeBtn.addEventListener("click", function () {
modal.style.display = "none";
});
window.addEventListener("click", function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
});
form.addEventListener("submit", function (event) {
event.preventDefault();
const fileInput = document.getElementById("fileInput");
console.log("File selected:", fileInput.files[0].name);
modal.style.display = "none";
});
});
// Toggle Menu in Mobile View
let nav_button = document.getElementById("navbar-sticky");
function onToggleMenu() {
nav_button.classList.toggle('hidden');
}
// Preloader
var loader = document.getElementById("preloader");
window.addEventListener("load", function () {
loader.style.display = "none";
})