-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
196 lines (178 loc) · 4.68 KB
/
main.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
(function() {
"use strict";
/**
* Easy selector helper function
*/
const select = (el, all = false) => {
el = el.trim();
return all ? [...document.querySelectorAll(el)] : document.querySelector(el);
};
/**
* Easy event listener function
*/
const on = (type, el, listener, all = false) => {
const selectEl = select(el, all);
if (selectEl) {
if (all) {
selectEl.forEach(e => e.addEventListener(type, listener));
} else {
selectEl.addEventListener(type, listener);
}
}
};
/**
* Easy on scroll event listener
*/
const onscroll = (el, listener) => {
el.addEventListener('scroll', listener);
};
/**
* Navbar links active state on scroll
*/
const navbarlinks = select('#navbar .scrollto', true);
const navbarlinksActive = () => {
const position = window.scrollY + 200;
navbarlinks.forEach(navbarlink => {
if (!navbarlink.hash) return;
const section = select(navbarlink.hash);
if (!section) return;
if (position >= section.offsetTop && position <= (section.offsetTop + section.offsetHeight)) {
navbarlink.classList.add('active');
} else {
navbarlink.classList.remove('active');
}
});
};
window.addEventListener('load', navbarlinksActive);
onscroll(document, navbarlinksActive);
/**
* Scrolls to an element with header offset
*/
const scrollto = (el) => {
const header = select('#header');
let offset = header.offsetHeight;
if (!header.classList.contains('header-scrolled')) {
offset -= 16;
}
const elementPos = select(el).offsetTop;
window.scrollTo({
top: elementPos - offset,
behavior: 'smooth'
});
};
/**
* Toggle .header-scrolled class to #header when page is scrolled
*/
const selectHeader = select('#header');
if (selectHeader) {
const headerScrolled = () => {
selectHeader.classList.toggle('header-scrolled', window.scrollY > 100);
};
window.addEventListener('load', headerScrolled);
onscroll(document, headerScrolled);
}
/**
* Back to top button
*/
const backtotop = select('.back-to-top');
if (backtotop) {
const toggleBacktotop = () => {
backtotop.classList.toggle('active', window.scrollY > 100);
};
window.addEventListener('load', toggleBacktotop);
onscroll(document, toggleBacktotop);
}
/**
* Mobile nav toggle
*/
on('click', '.mobile-nav-toggle', function() {
select('#navbar').classList.toggle('navbar-mobile');
this.classList.toggle('bi-list');
this.classList.toggle('bi-x');
});
/**
* Mobile nav dropdowns activate
*/
on('click', '.navbar .dropdown > a', function(e) {
if (select('#navbar').classList.contains('navbar-mobile')) {
e.preventDefault();
this.nextElementSibling.classList.toggle('dropdown-active');
}
}, true);
/**
* Scroll with offset on links with a class name .scrollto
*/
on('click', '.scrollto', function(e) {
if (select(this.hash)) {
e.preventDefault();
const navbar = select('#navbar');
if (navbar.classList.contains('navbar-mobile')) {
navbar.classList.remove('navbar-mobile');
const navbarToggle = select('.mobile-nav-toggle');
navbarToggle.classList.toggle('bi-list');
navbarToggle.classList.toggle('bi-x');
}
scrollto(this.hash);
}
}, true);
/**
* Scroll with offset on page load with hash links in the URL
*/
window.addEventListener('load', () => {
if (window.location.hash && select(window.location.hash)) {
scrollto(window.location.hash);
}
});
/**
* Clients Slider
*/
new Swiper('.screens-slider', {
speed: 400,
loop: true,
autoplay: {
delay: 5000,
disableOnInteraction: false
},
slidesPerView: 'auto',
pagination: {
el: '.swiper-pagination',
type: 'bullets',
clickable: true
},
breakpoints: {
320: {
slidesPerView: 1,
spaceBetween: 20
},
575: {
slidesPerView: 2,
spaceBetween: 20
},
640: {
slidesPerView: 3,
spaceBetween: 20
},
992: {
slidesPerView: 4,
spaceBetween: 20
}
}
});
/**
* Initiate GLightbox
*/
const glightbox = GLightbox({
selector: '.glightbox'
});
/**
* Animation on scroll
*/
window.addEventListener('load', () => {
AOS.init({
duration: 1000,
easing: 'ease-in-out',
once: true,
mirror: false
});
});
})();