-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.html
54 lines (49 loc) · 1.26 KB
/
testing.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
<!DOCTYPE html>
<html>
<head>
<title>Toggle Button</title>
<style>
.toggle {
width: 60px;
height: 30px;
background-color: #ccc;
border-radius: 15px;
position: relative;
cursor: pointer;
}
.toggle .slider {
position: absolute;
top: 2px;
left: 2px;
width: 26px;
height: 26px;
background-color: #fff;
border-radius: 50%;
transition: transform 0.2s ease-in-out;
}
.toggle.on .slider {
transform: translateX(30px);
}
.toggle .text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class="toggle" onclick="toggleSwitch()">
<div class="slider"></div>
<div class="text">OFF</div>
</div>
<script>
function toggleSwitch() {
var toggle = document.querySelector('.toggle');
toggle.classList.toggle('on');
var text = document.querySelector('.text');
text.textContent = toggle.classList.contains('on') ? 'ON' : 'OFF';
}
</script>
</body>
</html>