<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>
* {
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;
top: 0;
left: 0;
width: 160px;
height: 160px;
background: linear-gradient(to bottom, #444, #222);
border-radius: 50%;
transform: scale(0.9);
box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5),
inset 0 4px 4px rgba(255, 255, 255, 2.5),
inset 0 -4px 4px rgba(255, 255, 255, 0.2);
transition: 0.9s;
}
#toggle.active .indicator{
left: 160px;
background: linear-gradient(to bottom, #eaeaea, #f9f9f9);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0),
inset 0 4px 4px rgba(255, 255, 255, 1),
inset 0 -4px 4px rgba(255, 255, 255, 1);
}
const body = document.querySelector('body');
const toggle = document.getElementById('toggle');
toggle.onclick = function(){
toggle.classList.toggle('active');
body.classList.toggle('active');
}