Skip to content

Instantly share code, notes, and snippets.

Created January 15, 2015 07:06
Show Gist options
  • Save anonymous/450c0f22b31c50d92cf4 to your computer and use it in GitHub Desktop.
Save anonymous/450c0f22b31c50d92cf4 to your computer and use it in GitHub Desktop.
Teardrop toggle
<div class="wrap">
<div class="toggle"></div>
</div>
var toggler = document.querySelector('.toggle');
toggler.addEventListener('mousedown',function(evt){
toggle();
});
function toggle() {
if(toggler.classList.contains('enabled')) {
toggler.classList.remove('enabled');
} else {
toggler.classList.add('enabled');
}
}
setTimeout(toggle, 500);
setTimeout(toggle, 3000);
.wrap
{
width:400px;
margin:auto;
top:40%;
border:10px solid #c0c0c0;
border-radius:20px;
padding:30px;
margin-top:80px;
font-size:60pt;
font-family: Arial,sans-serif;
font-weight:bolder;
text-transform:uppercase;
}
.toggle
{
width:50px;
height:50px;
border:10px solid black;
border-radius:45px;
transition-duration:1s;
left:175px;
transform:rotate(45deg);
position:relative;
top:6px;
background-color:red;
border-bottom-left-radius:0px;
cursor:pointer;
display:inline-block;
}
.toggle.enabled {
background-color:green;
border-radius:45px;
border-bottom-left-radius:45px;
border-top-right-radius:0px;
}
.toggle::before
{
display:inline-block;
transform:rotate(-45deg);
content:"OFF";
transition-duration:1s;
position:absolute;
left:-145px;
top:75px;
}
.toggle::after
{
display:inline-block;
transform:rotate(-45deg);
content:"ON";
position:absolute;
transition-duration:1s;
top:-110px;
left:55px;
}
.toggle.enabled::before {
color:grey;
}
.toggle.enabled::after {
color:green;
}
.toggle::before {
color:red;
}
.toggle::after {
color:grey;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment