-
Notifications
You must be signed in to change notification settings - Fork 0
/
toggle2.html
89 lines (79 loc) · 2.39 KB
/
toggle2.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Toggle 2</title>
<style>
* {
padding: 0;
margin: 0;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #2b2b2b;
transition: .5s;
}
body.active {
background: #f8f8f8;
}
#toggle {
position: relative;
width: 260px;
height: 130px;
display: block;
border-radius: 130px;
background: #222;
box-shadow: inset 0 8px 60px rgba(0, 0, 0, .1),
inset 0 8px 8px rgba(0, 0, 0, .1),
inset 0 -4px 4px rgba(0, 0, 0, .1);
cursor: pointer;
transition: .5s;
}
#toggle.active {
background: #f8f8f8;
box-shadow: inset 0 8px 60px rgba(0, 0, 0, .1),
inset 0 8px 8px rgba(255, 255, 255, .1),
inset 0 -4px 4px rgba(255, 255, 255, .1);
}
#toggle .indicator {
width: 130px;
height: 130px;
position: absolute;
border-radius: 50%;
top: 0;
left: 0;
background: linear-gradient(to bottom, #444, #222);
transform: scale(0.9);
box-shadow: 0 8px 40px rgba(0, 0, 0, .5),
inset 0 4px 4px rgba(255, 255, 255, .2),
inset 0 -4px 4px rgba(255, 255, 255, .2);
transition: .5s;
}
#toggle.active .indicator {
left: 130px;
background: linear-gradient(to bottom, #eaeaea, #f8f8f8);
box-shadow: 0 8px 40px rgba(0, 0, 0, .5),
inset 0 4px 4px rgba(255, 255, 255, 1),
inset 0 -4px 4px rgba(255, 255, 255, 1);
}
</style>
</head>
<body>
<div id="toggle">
<i class="indicator"></i>
</div>
<script>
let body = document.querySelector('body')
let toggle = document.getElementById('toggle')
toggle.onclick = () => {
toggle.classList.toggle('active')
body.classList.toggle('active')
}
</script>
</body>
</html>