-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
84 lines (77 loc) · 3.28 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
document.querySelectorAll('[data-toggle~="navbar-submenu-content"]').forEach(el => {
el.addEventListener('click', function(e){
e.preventDefault();
this.closest('.navbar-submenu-wrapper').querySelectorAll('[data-toggle~="navbar-submenu"]').forEach(item => {
item.classList.remove('active');
});
this.classList.add('active');
this.closest('.navbar-submenu-wrapper').querySelectorAll('.navbar-submenu-content-wrapper').forEach(item => {
item.classList.remove('active');
});
document.querySelector(this.dataset.target).classList.add('active');
});
})
document.querySelector('.navbar-toggle').addEventListener('click', function(e){
e.preventDefault();
document.querySelector('.nav-menu-wrapper').classList.add('navbar-active');
});
document.querySelectorAll('[data-dismiss="navbar-submenu"]').forEach(el=> {
el.addEventListener('click', function(e) {
e.preventDefault();
this.closest('.navbar-active').classList.remove('navbar-active');
})
})
document.querySelectorAll('[data-dismiss="navbar-menu"]').forEach(el=> {
el.addEventListener('click', function(e) {
e.preventDefault();
document.querySelectorAll('.navbar-active').forEach(el=> el.classList.remove('navbar-active'))
})
})
document.querySelectorAll('[data-toggle~="navbar-submenu"]').forEach(el=> {
el.addEventListener('click', function(e) {
e.preventDefault()
if(window.innerWidth > 767) return
document.querySelector(this.dataset.target).classList.add('navbar-active');
})
});
// start: Header
const headerImage = document.querySelector('.header-image')
const headerImageIndicator = document.querySelector('.header-image-indicator')
let activeImage = 0
Array.from(headerImageIndicator.children).forEach((el, idx) => {
el.addEventListener('click', function(e) {
e.preventDefault()
Array.from(headerImage.children).forEach(item => item.classList.remove('active'));
headerImage.children[idx].classList.add('active');
Array.from(headerImageIndicator.children).forEach(item => item.classList.remove('active'));
this.classList.add('active');
activeImage = idx;
})
});
function carousel(){
Array.from(headerImage.children).forEach(item => item.classList.remove('active'));
headerImage.children[activeImage].classList.add('active');
Array.from(headerImageIndicator.children).forEach(item => item.classList.remove('active'));
headerImageIndicator.children[activeImage].classList.add('active');
if(activeImage < headerImage.children.length - 1){
activeImage++;
}else{
activeImage = 0;
}
setTimeout(function(){
requestAnimationFrame(carousel);
}, 5000)
}
carousel();
document.querySelectorAll('[data-slide="prev"]').forEach(el => {
el.addEventListener('click', function(e){
e.preventDefault();
document.querySelector(this.dataset.target).scrollLeft += document.querySelector(this.dataset.target).offsetWidth;
});
});
document.querySelectorAll('[data-slide="next"]').forEach(el => {
el.addEventListener('click', function(e){
e.preventDefault();
document.querySelector(this.dataset.target).scrollLeft -= document.querySelector(this.dataset.target).offsetWidth;
});
});