-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
67 lines (56 loc) · 1.87 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
const buttonToUp = document.querySelector(".button__scroll");
const navbar = document.querySelector(".header");
const changeHeader = () => {
if (window.pageXOffset > 140 || document.documentElement.scrollTop > 140) {
buttonToUp.classList.add("visible");
navbar.classList.add("shrink");
} else {
buttonToUp.classList.remove("visible");
navbar.classList.remove("shrink");
}
};
const changeHeaderTable = () => {
if (window.pageXOffset > 80 || document.documentElement.scrollTop > 80) {
buttonToUp.classList.add("visible");
navbar.classList.add("shrink--table");
} else {
buttonToUp.classList.remove("visible");
navbar.classList.remove("shrink--table");
}
};
const progressScrollbar = () => {
const scroll = window.scrollY;
const screenWidth = window.innerWidth;
const gif = document.querySelector(".gif-container");
const newPosition =
(scroll /
(document.documentElement.scrollHeight - window.innerHeight)) *
(screenWidth - 125);
gif.style.left = newPosition + "px";
};
window.addEventListener("scroll", progressScrollbar);
window.addEventListener("scroll", function () {
progressScrollbar();
if (window.innerWidth <= 825) {
changeHeaderTable();
} else {
changeHeader();
}
});
buttonToUp.addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
});
// burger menu
const burgerButton = document.querySelector(".button__burger");
const listMenu = document.querySelector(".header__nav");
burgerButton.addEventListener("click", () => {
burgerButton.classList.toggle("button__burger--active");
if (burgerButton.classList.contains("button__burger--active") === true) {
listMenu.classList.add("opacity");
} else {
listMenu.classList.remove("opacity");
}
});