-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle Switch js.html
58 lines (57 loc) · 1.22 KB
/
toggle Switch js.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
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Toggle Switch Js</title>
<style>
*{
margin:0;
padding:0;
box-sizing:border-box;
}
body{
min-height:100vh;
display:flex;
align-items:center;
justify-content:center;
background:#04004a;
}
.main{
position:relative;
width:100px;
height:50px;
background:#28009d;
box-shadow:0 0 30px #0b072a;
transition:0.5s;
border-radius:30px;
}
.main .checkbox{
position:absolute;
top:10px;
left:10px;
width:30px;
height:30px;
background:#ffffff;
box-shadow:0 0 5px #ffffff;
transition:0.5s;
border-radius:50%;
}
.active{
background:#00bfff;
}
.active .checkbox{
transform:translateX(50px);
}
</style>
</head>
<body>
<div class="main">
<div class="checkbox"></div>
</div>
<script>
let main = document.querySelector(".main");
main.addEventListener("click", function(){
main.classList.toggle("active");
});
</script>
</body>
</html>