-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
36 lines (31 loc) · 1.11 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
const themeToggle = document.querySelector("#theme-toggle");
const backtotop = document.querySelector("#backtotop");
function enableDarkMode() {
document.body.classList.remove("light-theme");
document.body.classList.add("dark-theme");
themeToggle.setAttribute("aria-label", "التحويل للوضع الفاتح");
}
function enableLightMode() {
document.body.classList.add("light-theme");
document.body.classList.remove("dark-theme");
themeToggle.setAttribute("aria-label", "التحويل للوضع الداكن");
}
document.body.classList.contains("light-theme")
? enableLightMode()
: enableDarkMode();
themeToggle.addEventListener("click", () => {
document.body.classList.contains("light-theme")
? enableDarkMode()
: enableLightMode();
});
window.addEventListener("scroll", () => {
if (window.scrollY > 600) {
backtotop.style.opacity = "100";
backtotop.style.visibility = "visible";
backtotop.style.transform = "translateY(0%)";
} else {
backtotop.style.opacity = "0";
backtotop.style.transform = "translateY(8%)";
backtotop.style.visibility = "hidden";
}
});