-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
108 lines (90 loc) · 2.91 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Typing animation
typed = new Typed(`.type`, {
strings: ["Virtual Assistance", "Frontend Developer", "Video Editor"],
typeSpeed: 100,
backSpeed: 100,
loop: true,
});
// Scroller progress
window.addEventListener(`scroll`, () => {
let scroller = document.querySelector(".scroller");
let height =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
let scrollTop = document.documentElement.scrollTop;
scroller.style.width = `${(scrollTop / height) * 100}%`;
});
// Scroll to top
span = document.querySelector(".scroll");
document.body.onscroll = () => {
if (scrollY > 100) {
span.classList.add("active");
} else {
span.classList.remove("active");
}
};
span.onclick = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};
// dark mode switch
let btn = document.querySelector(".darkModeButton");
btn.addEventListener("click", () => {
if (!localStorage.getItem("darkMode")) {
localStorage.setItem("darkMode", "true");
document.documentElement.style.setProperty("--background", "black");
document.body.classList.add("darkMode");
btn.src = "/img/moon.svg";
} else if (localStorage.getItem("darkMode") === "true") {
localStorage.setItem("darkMode", "false");
document.documentElement.style.setProperty("--background", "white");
document.body.classList.remove("darkMode");
btn.src = "/img/sun.svg";
} else if (localStorage.getItem("darkMode") === "false") {
localStorage.setItem("darkMode", "true");
document.documentElement.style.setProperty("--background", "black");
document.body.classList.add("darkMode");
btn.src = "/img/moon.svg";
}
});
if (localStorage.getItem("darkMode") === "false") {
document.documentElement.style.setProperty("--background", "white");
document.body.classList.remove("darkMode");
btn.src = "/img/sun.svg";
} else if (localStorage.getItem("darkMode") === "true") {
document.documentElement.style.setProperty("--background", "black");
document.body.classList.add("darkMode");
btn.src = "/img/moon.svg";
}
// slider
let left = document.getElementById("left-side");
let handleOnMove = (e) => {
let position = (e.clientX / window.innerWidth) * 100;
left.style.width = `${position}%`;
};
document.onmousemove = (e) => handleOnMove(e);
document.ontouchmove = (e) => handleOnMove(e.touches[0]);
// show on scroll
let observer = new IntersectionObserver((e) => {
e.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("show");
}
});
});
let hiddenElement = document.querySelectorAll(".hidden");
hiddenElement.forEach((e) => observer.observe(e));
//Scoial button functions
let social = document.querySelector(".shape");
social.addEventListener("click", () => {
social.classList.toggle("active");
});
document.body.onscroll = () => {
if (scrollY > 50) {
social.classList.add("active");
} else {
social.classList.remove("active");
}
};