generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
109 lines (101 loc) · 2.99 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
const speakers = [
{
name: 'Jonh Maxwell',
title: 'Leadership Expert',
description: 'Lisa is a celebrated motivational speaker',
image: './imgs/jonhmaxwell.png',
},
{
name: 'Lisa Nichols',
title: 'Transformational Speaker/Coach',
description: 'Lisa is a celebrated motivational speaker',
image: './imgs/lisanichols.jpeg',
},
{
name: ' Noura Al Kaabi',
title: 'Minister',
description: 'Lisa is a celebrated motivational speaker',
image: './imgs/noura.png',
},
{
name: 'Patrice Caine',
title: 'CEO',
description: 'Lisa is a celebrated motivational speaker',
image: './imgs/caine.png',
},
{
name: 'Mateo Renzi',
title: 'Prime Ministerh',
description: 'Lisa is a celebrated motivational speaker',
image: './imgs/renzi.png',
},
{
name: 'Ruth Porat',
title: 'Senior',
description: 'Lisa is a celebrated motivational speaker',
image: './imgs/porat.png',
},
];
const hambuger = document.querySelector('.div-logo');
const mobileMenu = document.querySelector('.mobile-menu');
const faMark = document.querySelector('.fa-xmark');
const lists = document.querySelectorAll('.na-list');
const speakerApp = document.querySelector('.speaker-container');
const moreSpeaker = document.querySelector('.more');
const navBar = document.querySelector('.navbar');
const openMenu = () => {
mobileMenu.classList.add('active-menu');
};
const closeMenu = () => {
mobileMenu.classList.remove('active-menu');
};
hambuger.addEventListener('click', openMenu);
faMark.addEventListener('click', closeMenu);
lists.forEach((list) => {
list.addEventListener('click', closeMenu);
});
let elt = speakers.slice(0, 2);
const displaySpeaker = () => {
elt.forEach((item) => {
speakerApp.innerHTML += `
<div class="speaker">
<img src=${item.image} alt="">
<div class="speaker-id">
<h3>${item.name}</h3>
<h4 id="job">${item.title}</h4>
<p>${item.description}</p>
</div>
</div>
`;
});
};
const loadMore = () => {
if (document.querySelectorAll('.speaker').length < speakers.length) {
elt = speakers.slice(2, speakers.length);
displaySpeaker();
moreSpeaker.innerHTML = 'Less <i class="fa fa-angle-up" aria-hidden="true">';
} else {
speakerApp.innerHTML = '';
elt = speakers.slice(0, 2);
displaySpeaker();
moreSpeaker.innerHTML = 'More <i class="fa fa-angle-down" aria-hidden="true">';
}
};
function myFunction(x) {
if (x.matches) { // If media query matches
speakerApp.innerHTML = '';
elt = speakers.slice(0, 2);
displaySpeaker();
moreSpeaker.addEventListener('click', loadMore);
} else {
speakerApp.innerHTML = '';
elt = speakers.slice(0, speakers.length);
displaySpeaker();
}
}
window.addEventListener('scroll', () => {
navBar.classList.toggle('nav-border', window.scrollY > 0);
});
const x = window.matchMedia('(max-width: 768px)');
myFunction(x);
x.addListener(myFunction);