Skip to content

Instantly share code, notes, and snippets.

Created January 23, 2017 22:30
Show Gist options
  • Save anonymous/9b993012ee6f056c182c5e337a15864a to your computer and use it in GitHub Desktop.
Save anonymous/9b993012ee6f056c182c5e337a15864a to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/dejilat
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.togglePill {
background-color: #00e600;
width: 60px;
border: 2px solid #00e600;
border-radius: 5px;
box-shadow: 1px 1px 5px #888;
cursor: pointer;
color: white;
transition: background-color 0.3s, border-color 0.3s;
transition-timing-function: ease-in-out;
}
.togglePill .togglePill-content {
padding: 0 10px;
border-radius: 5px;
background: linear-gradient(to right, #00e600 90%, white 10%); /* pill-width: 10% * 60px = 6px */
background-repeat: repeat-y;
transition: background-position 0.3s;
transition-timing-function: ease-in-out;
animation: showhide 0.3s;
}
.togglePill .togglePill-content:after {
text-align: center;
}
.togglePill.togglePill-true {
background-color: #00e600;
border-color: #00e600;
}
.togglePill.togglePill-false {
background-color: red;
border-color: red;
}
.togglePill.togglePill-true .togglePill-content:after {
content: "True";
}
.togglePill.togglePill-false .togglePill-content:after {
content: "False";
}
.togglePill.togglePill-true .togglePill-content {
background-position: 0px;
width: 40px;
}
.togglePill.togglePill-false .togglePill-content {
/* Hide the entire linear gradient except the "pill" */
background-position: -54px; /* pill-width - 60px = -54px */
width: 40px;
}
@keyframes showhide {
0% {color: rgba(0, 230, 0, 0);}
89% {color: rgba(0, 230, 0, 0);}
90% {color: rgba(0, 230, 0, 1);}
}
</style>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<div class="togglePill togglePill-true">
<div class="togglePill-content"></div>
</div>
<script id="jsbin-javascript">
$('.togglePill').click(function() {
$(this).toggleClass('togglePill-true')
.toggleClass('togglePill-false')
})
</script>
<script id="jsbin-source-css" type="text/css">.togglePill {
background-color: #00e600;
width: 60px;
border: 2px solid #00e600;
border-radius: 5px;
box-shadow: 1px 1px 5px #888;
cursor: pointer;
color: white;
transition: background-color 0.3s, border-color 0.3s;
transition-timing-function: ease-in-out;
}
.togglePill .togglePill-content {
padding: 0 10px;
border-radius: 5px;
background: linear-gradient(to right, #00e600 90%, white 10%); /* pill-width: 10% * 60px = 6px */
background-repeat: repeat-y;
transition: background-position 0.3s;
transition-timing-function: ease-in-out;
animation: showhide 0.3s;
}
.togglePill .togglePill-content:after {
text-align: center;
}
.togglePill.togglePill-true {
background-color: #00e600;
border-color: #00e600;
}
.togglePill.togglePill-false {
background-color: red;
border-color: red;
}
.togglePill.togglePill-true .togglePill-content:after {
content: "True";
}
.togglePill.togglePill-false .togglePill-content:after {
content: "False";
}
.togglePill.togglePill-true .togglePill-content {
background-position: 0px;
width: 40px;
}
.togglePill.togglePill-false .togglePill-content {
/* Hide the entire linear gradient except the "pill" */
background-position: -54px; /* pill-width - 60px = -54px */
width: 40px;
}
@keyframes showhide {
0% {color: rgba(0, 230, 0, 0);}
89% {color: rgba(0, 230, 0, 0);}
90% {color: rgba(0, 230, 0, 1);}
}</script>
<script id="jsbin-source-javascript" type="text/javascript">$('.togglePill').click(function() {
$(this).toggleClass('togglePill-true')
.toggleClass('togglePill-false')
})</script></body>
</html>
.togglePill {
background-color: #00e600;
width: 60px;
border: 2px solid #00e600;
border-radius: 5px;
box-shadow: 1px 1px 5px #888;
cursor: pointer;
color: white;
transition: background-color 0.3s, border-color 0.3s;
transition-timing-function: ease-in-out;
}
.togglePill .togglePill-content {
padding: 0 10px;
border-radius: 5px;
background: linear-gradient(to right, #00e600 90%, white 10%); /* pill-width: 10% * 60px = 6px */
background-repeat: repeat-y;
transition: background-position 0.3s;
transition-timing-function: ease-in-out;
animation: showhide 0.3s;
}
.togglePill .togglePill-content:after {
text-align: center;
}
.togglePill.togglePill-true {
background-color: #00e600;
border-color: #00e600;
}
.togglePill.togglePill-false {
background-color: red;
border-color: red;
}
.togglePill.togglePill-true .togglePill-content:after {
content: "True";
}
.togglePill.togglePill-false .togglePill-content:after {
content: "False";
}
.togglePill.togglePill-true .togglePill-content {
background-position: 0px;
width: 40px;
}
.togglePill.togglePill-false .togglePill-content {
/* Hide the entire linear gradient except the "pill" */
background-position: -54px; /* pill-width - 60px = -54px */
width: 40px;
}
@keyframes showhide {
0% {color: rgba(0, 230, 0, 0);}
89% {color: rgba(0, 230, 0, 0);}
90% {color: rgba(0, 230, 0, 1);}
}
$('.togglePill').click(function() {
$(this).toggleClass('togglePill-true')
.toggleClass('togglePill-false')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment