-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
216 lines (165 loc) · 5.26 KB
/
main.js
File metadata and controls
216 lines (165 loc) · 5.26 KB
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
/*
* Designed & Coded by: Ritik Kumar
*/
const loader = document.querySelector('.loader');
window.addEventListener('load', () => {
loader.classList.add('stop');
setTimeout(() => {
loader.style.display = 'none';
}, 5000);
});
/*========-- 02) Current Page Active-link --========*/
const activeLink = document.querySelectorAll('.active-link');
const currLocation = location.href;
activeLink.forEach(actLink => {
if (actLink.href === currLocation) {
actLink.classList.add('current-link');
}
actLink.addEventListener('click', (e) => {
e.preventDefault();
});
});
/*========-- 03) on Window Scroll (sticky-header, scrollTop-btn & scroll-spy) --========*/
const header = document.querySelector('#header');
const scrollTopBtn = document.querySelector('.scroll-top');
window.addEventListener('scroll', () => {
const currentTop = window.scrollY;
// Sticky Header
if (currentTop > 100) {
header.classList.add('sticky');
}
else {
header.classList.remove('sticky');
}
// Scroll-to-top btn
if (currentTop > 1000) {
scrollTopBtn.style.transform = 'translateY(0)';
}
else {
scrollTopBtn.style.transform = 'translateY(100px)';
}
// Scroll-spy
const sections = document.querySelectorAll('section');
const navLinks = document.querySelectorAll('.nav-list a');
sections.forEach(currSection => {
let sectionId = currSection.getAttribute('id');
let sectionHeight = currSection.offsetHeight;
let sectionTop = currSection.offsetTop;
if (currentTop >= (sectionTop - sectionHeight / 3)) {
navLinks.forEach(currLink => {
currLink.classList.remove('active-link');
const hrefValue = currLink.getAttribute('href').substring(1);
if (hrefValue === sectionId) {
currLink.classList.add('active-link');
}
});
}
});
});
const sidebar = document.querySelector('#side-bar');
const sidebarBtn = document.querySelector('.sidebar-btn');
sidebarBtn.addEventListener('click', () => {
sidebar.classList.toggle('open');
});
// closing the Sidebar on clicking Outside or any of the Links inside it
document.addEventListener('click', (e) => {
if (e.target.id !== 'side-bar' && e.target.className !== 'sidebar-btn') {
sidebar.classList.remove('open');
}
});
const galleryImgs = document.querySelectorAll('.item-box img');
const lightboxImg = document.querySelector('.lightbox img');
const lightboxWrapper = document.querySelector('.lightbox-wrapper');
const lightboxClose = document.querySelector('.lightbox-close');
galleryImgs.forEach(currImg => {
currImg.addEventListener('click', () => {
let imgSrc = currImg.getAttribute('src');
lightboxImg.setAttribute('src', imgSrc);
document.documentElement.classList.add('overflow-hide');
lightboxWrapper.classList.add('visible');
});
});
// closing the Lightbox on clicking outside of it
window.addEventListener('click', (e) => {
if (e.target === lightboxWrapper) {
document.documentElement.classList.remove('overflow-hide');
lightboxWrapper.classList.remove('visible')
}
});
// Reviews Swiper
const swiper2 = new Swiper('.reviews-swiper', {
effect: "coverflow",
grabCursor: true,
speed: 600,
loop: true,
loopedSlides: 4,
centeredSlides: true,
slideToClickedSlide: true,
slidesPerView: "auto",
coverflowEffect: {
rotate: 0,
stretch: 0,
depth: 100,
modifier: 2,
slideShadows: false,
},
autoplay: {
delay: 3500,
disableOnInteraction: false,
},
pagination: {
el: ".reviews-swiper .swiper-pagination",
dynamicBullets: true,
clickable: true,
},
keyboard: {
enabled: true,
onlyInViewport: false,
}
});
// =============For Silder Photo Slider=============
// =============For Silder Photo Slider=============
let items = document.querySelectorAll('.slider .list .item');
let next = document.getElementById('next');
let prev = document.getElementById('prev');
let thumbnails = document.querySelectorAll('.thumbnail .item');
// config param
let countItem = items.length;
let itemActive = 0;
// event next click
next.onclick = function(){
itemActive = itemActive + 1;
if(itemActive >= countItem){
itemActive = 0;
}
showSlider();
}
//event prev click
prev.onclick = function(){
itemActive = itemActive - 1;
if(itemActive < 0){
itemActive = countItem - 1;
}
showSlider();
}
function showSlider(){
// remove item active old
let itemActiveOld = document.querySelector('.slider .list .item.active');
let thumbnailActiveOld = document.querySelector('.thumbnail .item.active');
itemActiveOld.classList.remove('active');
thumbnailActiveOld.classList.remove('active');
// active new item
items[itemActive].classList.add('active');
thumbnails[itemActive].classList.add('active');
}
// click thumbnail
thumbnails.forEach((thumbnail, index) => {
thumbnail.addEventListener('click', () => {
itemActive = index;
showSlider();
})
})
// auto run slider
let refreshInterval = setInterval(() => {
next.click();
}, 5000);