-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
67 lines (56 loc) · 1.91 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
let myIndex = 0;
const mobileMenu = document.querySelector(".page-header__mobile");
const mobileMenuIcon = document.querySelector(".fa-bars");
const searchPanel = document.querySelector(".search");
const searchForm = document.querySelector(".search__form");
const searchInput = document.querySelector(".search__input");
const searchSubmit = document.querySelector(".search__submit");
const searchClose = document.querySelector(".search__close");
const searchIcon = document.querySelector(".page-header__search");
const bodyElem = document.querySelector(".page");
const nav = document.querySelector(".page-header__nav");
// Search panel
searchIcon.addEventListener("click", () => {
bodyElem.classList.add("page--overflow-hidden");
searchPanel.classList.add("search--active");
searchInput.focus();
});
searchSubmit.addEventListener("click", () => {
searchForm.submit();
});
searchClose.addEventListener("click", () => {
bodyElem.classList.remove("page--overflow-hidden");
searchPanel.classList.remove("search--active");
});
window.addEventListener("resize", () => {
if (window.innerWidth <= 767) {
bodyElem.classList.remove("page--overflow-hidden");
searchPanel.classList.remove("search--active");
}
});
// Mobile menu
mobileMenu.addEventListener("click", () => {
nav.classList.toggle("active");
if (mobileMenuIcon.classList.contains("fa-bars")) {
mobileMenuIcon.classList.remove("fa-bars");
mobileMenuIcon.classList.add("fa-xmark");
}
else {
mobileMenuIcon.classList.remove("fa-xmark");
mobileMenuIcon.classList.add("fa-bars");
}
});
// Automatic Slideshow
carousel();
function carousel() {
const slides = document.getElementsByClassName("slide");
for (let i = 0; i < slides.length; i++) {
slides[i].classList.add("hide");
}
myIndex++;
if (myIndex > slides.length) {
myIndex = 1;
}
slides[myIndex-1].classList.remove("hide");
setTimeout(carousel, 5000);
}