-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
179 lines (150 loc) · 5.07 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
$(document).ready(function(){
// sidebar toggle
$("#navbar-show-btn").click(() => $('.navbar-collapse').removeClass('translate-x-full'));
$('#navbar-hide-btn').click(() => $('.navbar-collapse').addClass('translate-x-full'));
// stop transitin on resize
let resizeTimer;
$(window).on('resize', () => {
$(document.body).addClass('resize-animation-stopper');
clearTimeout(resizeTimer);
resizeTimer = setTimeout(() => {
$(document.body).removeClass('resize-animation-stopper');
}, 400);
});
// game slider
$('.game-slider').slick({
className: "center",
arrows: true,
centerMode: true,
infinite: true,
centerPadding: "60px",
slidesToShow: 3,
slidesToScroll: 1,
speed: 500,
autoplay: true,
dots: true,
responsive: [
{
breakpoint: 1400,
settings: {
slidesToShow: 3,
}
},
{
breakpoint: 992,
settings: {
slidesToShow: 2,
initialSlide: 2
}
},
{
breakpoint: 768,
settings: {
slidesToShow: 1,
dots: false
}
}
]
});
// categorywise filtering
let buttonGroup = $('.button-group button');
let categoryItemsList = $('.category-item');
let initialActiveCategory = $($(buttonGroup)[0]).data('filter');
const setActiveButton = (categoryName) => {
jQuery.each(buttonGroup, function(index, buttonItem){
if($(buttonItem).data('filter') == categoryName){
$(buttonItem).addClass('active-filter-button');
} else {
$(buttonItem).removeClass('active-filter-button');
}
})
}
const filterItems = (categoryName) => {
jQuery.each(categoryItemsList, function(index, categoryItem){
if($(categoryItem).hasClass(categoryName)){
$(categoryItem).css('display', 'block');
} else {
$(categoryItem).css('display', 'none');
}
})
}
setActiveButton(initialActiveCategory);
filterItems(initialActiveCategory);
jQuery.each(buttonGroup, function(index, buttonItem){
$(buttonItem).click(function(){
let categoryName = $(buttonItem).data('filter');
setActiveButton(categoryName);
filterItems(categoryName);
});
})
});
let videoId;
if (window.innerWidth > 420) {
videoId = 'hero-video';
} else {
videoId = 'hero-video-mb';
}
const video = document.getElementById(videoId);
let loopCount = 0;
const maxLoopCount = 3; // Define the maximum number of loops
function loopVideo() {
console.log('Starting new loop');
const startTime = performance.now();
video.currentTime = 0;
video.play();
video.addEventListener('timeupdate', function onTimeUpdate() {
const elapsed = performance.now() - startTime;
console.log('Elapsed time:', elapsed);
if (elapsed >= 15000) {
console.log('Reached 15 seconds, pausing');
video.pause();
video.removeEventListener('timeupdate', onTimeUpdate);
loopCount++;
if (loopCount < maxLoopCount) {
console.log('Looping again...');
loopVideo();
} else {
console.log('Maximum loop count reached, stopping loop');
}
}
});
}
video.addEventListener('ended', () => {
console.log('Video ended');
});
video.addEventListener('error', (err) => {
console.error('Error!', err);
});
loopVideo();
// scroll up button js code
document.getElementById('scrollUpBtn').addEventListener('click', function() {
scrollToTop(1000); // Adjust the duration as needed
});
function scrollToTop(duration) {
var start = window.pageYOffset;
var startTime = 'now' in window.performance ? performance.now() : new Date().getTime();
function scrollStep() {
var now = 'now' in window.performance ? performance.now() : new Date().getTime();
var timeElapsed = now - startTime;
var easeInOutCubic = function (t) { return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1; };
window.scrollTo(0, start - start * easeInOutCubic(timeElapsed / duration));
if (timeElapsed < duration) {
requestAnimationFrame(scrollStep);
} else {
window.scrollTo(0, 0);
}
}
requestAnimationFrame(scrollStep);
}
// scroll button dissappear when the page is at the top:
window.addEventListener('scroll', function() {
var scrollUpBtn = document.getElementById('scrollUpBtn');
if (window.scrollY > window.innerHeight * 0.3) {
scrollUpBtn.style.opacity = '1';
scrollUpBtn.style.display = 'block';
scrollUpBtn.style.pointerEvents = 'auto'; // Re-enable pointer events
} else {
scrollUpBtn.style.opacity = '0';
scrollUpBtn.style.pointerEvents = 'none'; // Disable pointer events to prevent clicking while invisible
}
});