-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
135 lines (109 loc) · 3.53 KB
/
app.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
// preloader
const body = document.body;
const preloader = document.querySelector('.preloader');
window.addEventListener('load',()=>{
document.body.classList.add('active');
preloader.style.display = "none";
})
// nav toggler
const nav = document.querySelector('nav');
const toggleMenu = document.querySelector('.nav__menu')
toggleMenu.addEventListener('click',()=>{
nav.classList.toggle('nav__active');
})
// style navlink while on that specific section
const links = document.querySelectorAll('.nav__links li a');
const sections = document.querySelectorAll('.nav-section');
window.addEventListener('scroll', ()=>{
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
if(pageYOffset >= sectionTop - 100){
current = section.getAttribute('id');
}
})
links.forEach(link =>{
link.classList.remove('active');
document.querySelector(`.${current}-link`).classList.add('active');
})
})
// Prevent from opening more than one question
function handleAccordion(){
let accordionOpened = document.querySelectorAll('details[open]')
for(let item of accordionOpened){
if(this != item){
item.removeAttribute("open");
}
}
}
const accordions = document.querySelectorAll('details');
accordions.forEach(accordion=>{
accordion.addEventListener('click',handleAccordion);
})
//sliders
const swiper = new Swiper('.swiper', {
direction: 'horizontal',
loop: true,
slidesPerView: 'auto',
autoplay: {
delay: 2000,
disableOnInteraction: false
},
});
const swiperOne = new Swiper('.swiper1', {
direction: 'horizontal',
loop: true,
slidesPerView: 'auto',
autoplay: {
delay: 5000,
disableOnInteraction: false
},
pagination: {
el: '.swiper-pagination',
clickable: true
}
});
// Check if the user is scrolling down
window.addEventListener('scroll', ()=>{
const currentScroll = window.pageYOffset;
if(currentScroll > 0){
body.classList.add('scroll-down');
}else{
body.classList.remove('scroll-down');
}
const goTop = document.querySelector('.go-top');
if(currentScroll >= 620){
goTop.style.display = "flex";
}else{
goTop.style.display = "none";
}
})
// Add transition on scrolls
const fadeFromLeftElements = document.querySelectorAll('.fadeFromLeft');
const observer = new IntersectionObserver(entries =>{
entries.forEach(entry=>{
entry.isIntersecting && entry.target.classList.add('ffl-active');
})
})
fadeFromLeftElements.forEach(el => observer.observe(el));
const fadeFromRightElements = document.querySelectorAll('.fadeFromRight');
const observerTwo = new IntersectionObserver(entries =>{
entries.forEach(entry =>{
entry.isIntersecting && entry.target.classList.add('ffr-active');
})
})
fadeFromRightElements.forEach(el => observerTwo.observe(el));
const fadeFromBottomElements = document.querySelectorAll('.fadeFromBottom');
const observerThree = new IntersectionObserver(entries =>{
entries.forEach(entry =>{
entry.isIntersecting && entry.target.classList.add('ffb-active');
})
})
fadeFromBottomElements.forEach(el => observerThree.observe(el));
const fadeFromTopElements = document.querySelectorAll('.fadeFromTop');
const observerFour = new IntersectionObserver(entries =>{
entries.forEach(entry =>{
entry.isIntersecting && entry.target.classList.add('fft-active');
})
})
fadeFromTopElements.forEach(el => observerFour.observe(el));