-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml.js
More file actions
81 lines (70 loc) · 2.14 KB
/
Copy pathhtml.js
File metadata and controls
81 lines (70 loc) · 2.14 KB
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
// Nav
const nav = document.querySelector(".nav-menu");
const navigation = document.querySelector(".navigation");
const openBtn = document.querySelector(".hamburger");
const closeBtn = document.querySelector(".close");
const navLeft = nav.getBoundingClientRect().left;
openBtn.addEventListener("click", () => {
if (navLeft < 0) {
navigation.classList.add("show");
nav.classList.add("show");
document.body.classList.add("show");
}
});
closeBtn.addEventListener("click", () => { //dom
if (navLeft < 0) {
navigation.classList.remove("show");
nav.classList.remove("show");
document.body.classList.remove("show");
}
});
// Fixed Nav
const navBar = document.querySelector(".navigation");
const navHeight = navBar.getBoundingClientRect().height;
window.addEventListener("scroll", () => {
const scrollHeight = window.pageYOffset;
if (scrollHeight > navHeight) {
navBar.classList.add("fix-nav");
} else {
navBar.classList.remove("fix-nav");
}
});
// Scroll To
const links = [...document.querySelectorAll(".scroll-link")];
links.map(link => {
link.addEventListener("click", e => {
e.preventDefault();
const id = e.target.getAttribute("href").slice(1);
const element = document.getElementById(id);
const fixNav = navBar.classList.contains("fix-nav");
let position = element.offsetTop - navHeight;
if (!fixNav) {
position = position - navHeight;
}
window.scrollTo({
top: position,
left: 0,
});
navigation.classList.remove("show");
nav.classList.remove("show");
document.body.classList.remove("show");
});
});
// preloader
window.addEventListener("load", () => {
const loader = document.getElementById("pre-loader");
setTimeout(() => {
loader.classList.add("hide");
}, 2000);
});
// PopUp
const popup = document.querySelector(".popup");
const closePopup = document.querySelector(".popup-close");
closePopup.addEventListener("click", () => {
popup.classList.remove("show");
});
window.addEventListener("load", () => {
setTimeout(() => {
popup.classList.add("show");
}, 5000);
});