-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
64 lines (51 loc) · 1.81 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
var toggleButton = document.querySelector(".toggle-button");
var mobileNav = document.querySelector(".mobile-nav");
var closeButton = document.querySelector(".close-button");
toggleButton.addEventListener("click", function (e) {
e.preventDefault();
// mobileNav.classList.add("open");
mobileNav.classList.toggle("slide");
});
closeButton.addEventListener("click", function () {
// mobileNav.classList.remove("open");
mobileNav.classList.toggle("slide");
});
// close after click links
// Scroll nav
var nav = document.querySelector("nav");
window.addEventListener("scroll", () => {
if (window.scrollY > 50) {
nav.classList.add("scrolled");
} else {
nav.classList.remove("scrolled");
}
});
const header = document.querySelector(".header");
const cookieMessage = document.createElement("div");
cookieMessage.classList.add("cookie-message");
cookieMessage.innerHTML = `ما از کوکی ها برای بهبود تجربه کاربری شما استفاده میکنیم
<button class="btn light btn--close-cookie">فهمیدم!</button>`;
header.append(cookieMessage);
document
.querySelector(".btn--close-cookie")
.addEventListener("click", function () {
cookieMessage.remove();
});
// Smooth scrolling
document.querySelectorAll(".nav__link").forEach(function (el) {
el.addEventListener("click", function (e) {
e.preventDefault();
mobileNav.classList.toggle("slide");
const id = this.getAttribute("href");
console.log(id);
document.querySelector(id).scrollIntoView({ behavior: "smooth" });
});
});
document.querySelectorAll(".nav__link--desk").forEach(function (el) {
el.addEventListener("click", function (e) {
e.preventDefault();
const id = this.getAttribute("href");
console.log(id);
document.querySelector(id).scrollIntoView({ behavior: "smooth" });
});
});