-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
242 lines (198 loc) · 6.9 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
/* website navigation */
document.addEventListener("DOMContentLoaded", function() {
const sidebar = document.querySelector('.mobile-nav');
sidebar.style.display = 'none';
});
function show_mobile_nav() {
const sidebar = document.querySelector('.mobile-nav');
sidebar.style.display = 'block';
}
function hide_mobile_nav() {
const sidebar = document.querySelector('.mobile-nav');
sidebar.style.display = 'none';
}
/* preloader */
document.addEventListener('DOMContentLoaded', function () {
const progressText = document.getElementById('progress');
let progressValue = 0;
function updateProgress() {
progressText.innerText = `${progressValue}%`;
if (progressValue < 100) {
progressValue += 2;
setTimeout(updateProgress, 30);
} else {
// Wait for 0.5s before hiding the preloader
setTimeout(function () {
document.querySelector('.preloader').style.display = 'none';
}, 500);
}
}
updateProgress();
});
/* main site loader */
$(document).ready(function() {
let loader = $('.loader'), // Store loader element
loading = $('.loading').wrapInner('<div></div>'),
min = 20,
max = 70,
minMove = 10,
maxMove = 20;
startAnimation(loading);
loading.on('animationend webkitAnimationEnd oAnimationEnd', 'span:last-child', e => {
startAnimation(loading);
});
// Set CSS vars & generate spans if needed
function setCSSVars(elem, min, max, minMove, maxMove) {
let width = Math.ceil(elem.width()),
text = elem.text();
for(let i = 1; i < width; i++) {
let num = Math.floor(Math.random() * (max - min + 1)) + min,
numMove = Math.floor(Math.random() * (maxMove - minMove + 1)) + minMove,
dir = (i % 2 == 0) ? 1 : -1,
spanCurrent = elem.find('span:eq(' + i + ')'),
span = spanCurrent.length ? spanCurrent : $('<span />');
span.css({
'--x': i - 1 + 'px',
'--move-y': num * dir + 'px',
'--move-y-s': ((i % 2 == 0) ? num * dir - numMove : num * dir + numMove) + 'px',
'--delay': i * 10 + 'ms'
});
if(!spanCurrent.length) {
elem.append(span.text(text));
}
}
}
// Start animation
function startAnimation(elem) {
elem.removeClass('start');
setCSSVars(elem, min, max, minMove, maxMove);
void elem[0].offsetWidth;
elem.addClass('start');
// Hide loader and show site content after 3 seconds
setTimeout(function() {
loader.fadeOut(); // Fade out loader
// Show site content or execute any other actions
// Example: $('.site-content').fadeIn();
}, 3400);
}
});
/* custom cursor */
document.addEventListener('mousemove', function(e) {
document.querySelectorAll('.cursor')[0].style.left = e.clientX + 'px';
document.querySelectorAll('.cursor')[0].style.top = e.clientY + 'px';
setTimeout(function() {
document.querySelectorAll('.cursor')[1].style.left = e.clientX + 'px';
document.querySelectorAll('.cursor')[1].style.top = e.clientY + 'px';
}, 120);
});
document.querySelectorAll('a').forEach(function(link) {
link.addEventListener('mouseenter', function() {
document.querySelectorAll('.cursor').forEach(function(cursor) {
cursor.classList.add('big');
});
});
link.addEventListener('mouseleave', function() {
document.querySelectorAll('.cursor').forEach(function(cursor) {
cursor.classList.remove('big');
});
});
});
/* image slider */
var i_col1 = 0;
var i_col2 = 0;
var images_col1 = [
'assets/tour-dp-1.jpg',
'assets/tour-dp-2.jpg'
];
var images_col2 = [
'assets/tour-dp-3.jpg',
'assets/tour-dp-4.jpg'
];
var time_col1 = 8000; // Time for col-1
var time_col2 = 5000; // Time for col-2
function changeImgCol1() {
document.getElementById('slide1').src = images_col1[i_col1];
if (i_col1 < images_col1.length - 1) {
i_col1++;
} else {
i_col1 = 0;
}
setTimeout(changeImgCol1, time_col1);
}
function changeImgCol2() {
document.getElementById('slide2').src = images_col2[i_col2];
if (i_col2 < images_col2.length - 1) {
i_col2++;
} else {
i_col2 = 0;
}
setTimeout(changeImgCol2, time_col2);
}
window.onload = function() {
changeImgCol1();
changeImgCol2();
};
/* tour carousel */
//step 1: get DOM
let nextDom = document.getElementById('next');
let prevDom = document.getElementById('prev');
let carouselDom = document.querySelector('.carousel');
let SliderDom = carouselDom.querySelector('.carousel .list');
let thumbnailBorderDom = document.querySelector('.carousel .thumbnail');
let thumbnailItemsDom = thumbnailBorderDom.querySelectorAll('.item');
let timeDom = document.querySelector('.carousel .time');
thumbnailBorderDom.appendChild(thumbnailItemsDom[0]);
let timeRunning = 3000;
let timeAutoNext = 7000;
nextDom.onclick = function(){
showSlider('next');
}
prevDom.onclick = function(){
showSlider('prev');
}
let runTimeOut;
let runNextAuto = setTimeout(() => {
next.click();
}, timeAutoNext)
function showSlider(type){
let SliderItemsDom = SliderDom.querySelectorAll('.carousel .list .item');
let thumbnailItemsDom = document.querySelectorAll('.carousel .thumbnail .item');
if(type === 'next'){
SliderDom.appendChild(SliderItemsDom[0]);
thumbnailBorderDom.appendChild(thumbnailItemsDom[0]);
carouselDom.classList.add('next');
}else{
SliderDom.prepend(SliderItemsDom[SliderItemsDom.length - 1]);
thumbnailBorderDom.prepend(thumbnailItemsDom[thumbnailItemsDom.length - 1]);
carouselDom.classList.add('prev');
}
clearTimeout(runTimeOut);
runTimeOut = setTimeout(() => {
carouselDom.classList.remove('next');
carouselDom.classList.remove('prev');
}, timeRunning);
clearTimeout(runNextAuto);
runNextAuto = setTimeout(() => {
next.click();
}, timeAutoNext)
}
/* content reveal */
window.addEventListener('scroll', reveal);
function reveal()
{
var reveals = document.querySelectorAll('.reveal');
for (var i = 0; i < reveals.length; i++)
{
var windowheight = window.innerHeight;
var revealtop = reveals[i].getBoundingClientRect().top;
var revealpoint = 150;
if (revealtop < windowheight - revealpoint)
{
reveals[i].classList.add('active');
}
else
{
reveals[i].classList.remove('active');
}
}
}