-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolormodetoggle.html
More file actions
100 lines (82 loc) · 2.2 KB
/
colormodetoggle.html
File metadata and controls
100 lines (82 loc) · 2.2 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
:root {
--primary-clr: white;
--primary-label: black;
--secdary-label: white;
--white-ball: white;
--black-ball: black;
}
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
height: 100vh;
}
.wrapper{
height: 100svh;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
#switch {
width: 0;
height: 0;
visibility: hidden;
}
label{
display: block;
width: 100px;
height: 50px;
border-radius: 100px;
background: var(--primary-label);
position: relative;
transition: 0.5s;
}
label::after{
content: '';
width: 40px;
height: 40px;
border-radius: 70px;
background: var(--white-ball);
position: absolute;
top:5px;
left:5px;
transition: 0.5s;
}
#switch:checked + label::after{
background: var(--black-ball);
left:calc(100% - 5px);
transform: translateX(-100%);
}
#switch:checked + label{
background: var(--secdary-label);
}
label:active::after{
width: 60px;
}
</style>
</head>
<body>
<div class="wrapper">
<input type="checkbox" id="switch">
<label for="switch"></label>
</div>
<script>
let toggler = document.getElementById('switch')
toggler.addEventListener('click', ()=>{
toggler.checked === true
? document.body.style.backgroundColor ="black"
: document.body.style.backgroundColor ="white";
})
</script>
</body>
</html>