"button mode dark and light (Html + css + js)"
Bootstrap 4.1.1 Snippet by nghiaalden

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
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<!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>Document</title>
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div id="toggle">
<i class="indicator"></i>
</div>
<script type="text/javascript">
const body = document.querySelector('body');
const toggle = document.getElementById('toggle');
toggle.onclick = function(){
toggle.classList.toggle('active');
body.classList.toggle('active');
}
</script>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #2b2b2b;
/* transition: 0.5s; */
}
body.active{
background: white;
}
#toggle {
position: relative;
display: block;
width: 320px;
height: 160px;
border-radius: 160px;
background: #222;
transition: 0.5s;
cursor: pointer;
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);
}
#toggle.active{
background: white;
box-shadow: inset 0 2px 60px rgba(0, 0, 0, 0.1),
inset 0 2px 8px rgba(0, 0, 0, 0.1),
inset 0 -4px 4px rgba(0, 0, 0, 0.2);
}
#toggle .indicator{
position:absolute;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
const body = document.querySelector('body');
const toggle = document.getElementById('toggle');
toggle.onclick = function(){
toggle.classList.toggle('active');
body.classList.toggle('active');
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: