-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
62 lines (55 loc) · 1.77 KB
/
test.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dark/White Mode Toggle</title>
<style>
body {
transition: background-color 0.3s, color 0.3s;
}
.dark-mode {
background-color: #121212;
color: #ffffff;
}
.light-mode {
background-color: #ffffff;
color: #000000;
}
.toggle-button {
padding: 10px 20px;
margin: 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
.toggle-button.dark {
background-color: #ffffff;
color: #121212;
}
.toggle-button.light {
background-color: #121212;
color: #ffffff;
}
</style>
</head>
<body class="light-mode">
<button id="toggleButton" class="toggle-button dark">Switch to Dark Mode</button>
<script>
const toggleButton = document.getElementById('toggleButton');
const body = document.body;
toggleButton.addEventListener('click', () => {
if (body.classList.contains('light-mode')) {
body.classList.replace('light-mode', 'dark-mode');
toggleButton.textContent = 'Switch to Light Mode';
toggleButton.classList.replace('dark', 'light');
} else {
body.classList.replace('dark-mode', 'light-mode');
toggleButton.textContent = 'Switch to Dark Mode';
toggleButton.classList.replace('light', 'dark');
}
});
</script>
</body>
</html>