-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_switch_btn.html
164 lines (147 loc) · 4.24 KB
/
js_switch_btn.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Switch Button</title>
<style>
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
header{
width: 100%;
background-color: #F2C230;
}
h1{
font-family: "Poppins", sans-serif;
font-weight: 700;
font-style: normal;
font-size: 30px;
padding: 10px;
}
p{
font-family: "Poppins", sans-serif;
font-weight: 400;
font-style: normal;
color: white;
}
header img{
width: 4%;
height: 4%;
padding: 10px;
}
body{
display: flex;
flex-direction: column;
align-items: center;
justify-content: baseline;
background-color: #8C7161;
}
#bg-color{
width: 900vh;
padding: 10px;
height: 1900px;
background-image: repeating-conic-gradient(
from 45deg at 50% 50%,
rgb(223, 0, 0) 0deg 10deg,
rgb(247, 242, 0) 10deg 20deg,
rgb(0, 133, 167) 20deg 30deg,
rgb(167, 0, 153) 30deg 40deg);
filter: blur(3px);
z-index: -1;
position: fixed;
top: -90%;
opacity: 0;
transition: all 0.1s ease-in-out;
}
#bg-color.active{
animation: rotate-bg 5s linear infinite;
opacity: 100%;
}
#bg-color:not(.active){
animation: none;
opacity: 0;
transition: all 0.1s ease-in-out;
}
.switch{
width: 19%;
height: 110px;
border: 10px solid white;
position: absolute;
margin: 24%;
top: 0;
border-radius: 100px;
display: flex;
align-items: center;
justify-content: flex-start;
padding: 10px;
transition: all 0.3s ease-in-out;
box-shadow: 0px 0px 10px 3px rgb(87, 87, 87);
}
.switch.active{
border: 10px solid rgb(75, 253, 75);
background-color: rgb(0, 141, 0);
box-shadow:inset 0px 30px 50px 10px rgb(2, 48, 2);
}
.switch:not(.active){
border: 10px solid white;
background-color: transparent;
box-shadow: 0px 0px 10px 3px rgb(87, 87, 87);
}
.circle{
width: 80px;
height: 80px;
border-radius: 100px;
background-color: white;
cursor: pointer;
}
.circle.left{
margin-left: 61%;
transition: all 0.3s ease-in-out;
outline: 10px solid rgb(0, 70, 0);
box-shadow: inset 0px 0px 10px 3px rgb(87, 87, 87);
}
.circle:not(.left){
margin-left: 0;
transition: all 0.3s ease-in-out;
box-shadow: none;
}
@keyframes rotate-bg {
to{transform: rotate(0deg);}
from{transform: rotate(360deg);}
}
@keyframes btn-move {
to{transform: rotate(0deg);}
from{transform: rotate(360deg);}
}
</style>
</head>
<body>
<header>
<a href="index.html"><img src="immagini/icon/js_blank.svg" alt="logo"></a>
</header>
<div class="switch" id="switch-lg">
<div class="circle" id="circle"></div>
</div>
<div id="bg-color"></div>
<script>
const Switch = document.getElementById('switch-lg');
const circle = document.getElementById('circle');
const bg = document.getElementById('bg-color');
circle.addEventListener('click', function(){
var condition = this.className === 'left';
if (!condition) {
this.classList.toggle('left');
bg.classList.toggle('active');
Switch.classList.toggle('active');
} else {
this.classList.add('circle');
bg.classList.remove('active');
Switch.classList.toggle('active');
}
})
</script>
</body>
</html>