Switch Thing
by hiddenloop
HTML
<div class="switch">
<label for="qux">Uninstalled</label>
<input class="switch" type="checkbox" id="qux" />
<div class="thing"></div>
</div>
<div class="switch thinking">
<label for="bar">Installing…</label>
<input class="switch" type="checkbox" checked id="bar" />
<div class="thing"></div>
</div>
<div class="switch">
<label for="foo">Installed</label>
<input class="switch" type="checkbox" checked id="foo" />
<div class="thing"></div>
</div>
<div class="switch thinking">
<label for="baz">Uninstalling…</label>
<input class="switch" type="checkbox" id="baz" />
<div class="thing"></div>
</div>
CSS
body {
margin:4em;
font:300 normal 15px/1.5 Ubuntu, sans-serif;
}
.switch {
box-sizing:border-box;
position:relative;
padding:0 2.5em 0 0;
margin:1em 0;
}
.switch label {
position:absolute;
z-index:10;
padding-left:4em;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.switch input {
display:none;
}
.switch .thing {
display:inline-block;
position:relative;
width:3em;
height:1.5em;
vertical-align:bottom;
border-radius:3px;
background-color:#eee;
}
.switch .thing::before, .switch .thing::after {
box-sizing:border-box;
content:"";
display:block;
position:absolute;
left:0;
height:1.5em;
transition:all 100ms;
border-radius:2px;
}
.switch .thing::before {
width:3em;
border:1px solid #ccc;
box-shadow:inset 0 0 2px 0 rgba(10,10,10,0.2);
z-index:2;
}
.switch .thing::after {
width:1.5em;
background-color:#fff;
border:2px solid #ccc;
z-index:3;
}
.switch input:checked + .thing::before {
background-color:#38B44A;
border-color:#38B44A;
}
.switch input:checked + .thing::after {
left:1.5em;
border-color:#38B44A;
}
.switch.thinking .thing {
background-size: 30px 30px;
background-image: linear-gradient(45deg, rgba(0,0,0, 0.1) 25%, transparent 25%, transparent 50%, rgba(0,0,0, 0.1) 50%, rgba(0,0,0, 0.1) 75%, transparent 75%, transparent);
-webkit-animation: barberpole 0.6s linear infinite;
animation: barberpole 0.6s linear infinite;
}
.switch.thinking input:checked + .thing::before {
background-color:rgba(56,180,74,0.5);
border-color:rgba(56,180,74,0.5);
}
@-webkit-keyframes barberpole {
from {
background-position: 0 0;
}
to {
background-position: 60px 30px;
}
}
@keyframes barberpole {
from {
background-position: 0 0;
}
to...