forked from NageshMandal/Engineering-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
81 lines (75 loc) · 2.58 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Get the "return to top" button element
var returnToTopButton = document.getElementById('returnToTop');
// Function to scroll to the top of the page
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
}
// Function to toggle the visibility of the "return to top" button
function toggleReturnToTopButton() {
if (window.scrollY > 200) {
returnToTopButton.classList.add('active');
} else {
returnToTopButton.classList.remove('active');
}
}
// Add event listeners
window.addEventListener('scroll', toggleReturnToTopButton);
returnToTopButton.addEventListener('click', scrollToTop);
//! dark mode
const header = document.querySelector(".header");
const toggle = document.querySelector(".toggle-mode");
const body = document.querySelector("body");
const paragraph = document.querySelector("p");
const links = document.querySelectorAll(".nav-link");
const title = document.querySelectorAll("h2");
const para = document.querySelectorAll(".para");
const pcol = document.querySelector(".col-2 p");
if (localStorage.getItem("dark-mode") == "true") {
body.classList.add("dark-mode");
header.classList.add("header-dark-mode");
paragraph.classList.add("header-dark-mode");
links.forEach(function (e) {
e.classList.add("header-dark-mode");
});
document.querySelector(`.sun`).style.display = "inline-block";
document.querySelector(`.moon`).style.display = "none";
title.forEach(function (e) {
e.classList.add("dark-mode");
});
}
toggle.addEventListener("click", function (e) {
const nextIcon = e.target.getAttribute("data-set");
e.target.style.display = "none";
console.log(nextIcon);
// document.querySelector("")
if (nextIcon === "sun") {
body.classList.add("dark-mode");
header.classList.add("header-dark-mode");
paragraph.classList.add("header-dark-mode");
pcol.style.color="white";
links.forEach(function (e) {
e.classList.add("header-dark-mode");
});
document.querySelector(`.${nextIcon}`).style.display = "inline-block";
title.forEach(function (e) {
e.classList.add("dark-mode");
});
localStorage.setItem("dark-mode", true);
} else {
body.classList.remove("dark-mode");
header.classList.remove("header-dark-mode");
paragraph.classList.remove("header-dark-mode");
pcol.style.color="black";
links.forEach(function (e) {
e.classList.remove("header-dark-mode");
});
document.querySelector(`.${nextIcon}`).style.display = "inline-block";
title.forEach(function (e) {
e.classList.remove("dark-mode");
});
localStorage.setItem("dark-mode", false);
}
});