-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
64 lines (47 loc) · 1.5 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
'use strict';
const navbar = document.querySelector("[data-navbar]");
const navbarLinks = document.querySelectorAll("[data-nav-link]");
const navbarToggler = document.querySelector("[data-nav-toggler]");
navbarToggler.addEventListener("click", function () {
navbar.classList.toggle("active");
this.classList.toggle("active");
});
for (let i = 0; i < navbarLinks.length; i++) {
navbarLinks[i].addEventListener("click", function () {
navbar.classList.remove("active");
navbarToggler.classList.remove("active");
});
}
function toggleSearchBox() {
var searchBox = document.getElementById("searchBox");
var searchIcon = document.getElementById("searchIcon");
if (searchBox.style.width === "0px") {
searchBox.style.width = "200px"; // Expanded width
searchBox.style.padding = "10px";
} else {
searchBox.style.width = "0px"; // Initial width
searchBox.style.padding = "0px";
}
}
/**
* search toggle
*/
for (let i = 0; i < searchTogglers.length; i++) {
searchTogglers[i].addEventListener("click", function () {
searchBox.classList.toggle("active");
});
}
/**
* header
*/
const header = document.querySelector("[data-header]");
const backTopBtn = document.querySelector("[data-back-top-btn]");
window.addEventListener("scroll", function () {
if (window.scrollY >= 200) {
header.classList.add("active");
backTopBtn.classList.add("active");
} else {
header.classList.remove("active");
backTopBtn.classList.remove("active");
}
});