Last active
May 28, 2016 07:57
-
-
Save Diliprocks1986/eec058b113b3da819862cf66818f632a to your computer and use it in GitHub Desktop.
CSS Switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CSS Switch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="switch"> | |
<input type="checkbox" id="c1" /> | |
<label for="c1"></label> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background: #243142; | |
} | |
.switch { | |
input { | |
display: none; | |
} | |
label { | |
-webkit-appearance: none; | |
display: block; | |
height: 36px; | |
width: 62px; | |
border-radius: 50px; | |
margin: 100px auto 0; | |
background: #182029; | |
position: relative; | |
outline: none; | |
cursor: pointer; | |
overflow: hidden; | |
transition: 0.2s; | |
-webkit-transition: 0.2s; | |
-moz-transition: 0.2s; | |
&:before { | |
content: ''; | |
position: absolute; | |
top: 2px; | |
left: 2px; | |
height: 32px; | |
width: 32px; | |
background: white; | |
border-radius: 50%; | |
border-radius: 16px; | |
z-index: 1; | |
animation: uncheck 0.3s ease-out; | |
-webkit-animation: uncheck 0.3s ease-out; | |
-moz-animation: uncheck 0.3s ease-out; | |
transform-origin: 0 0; | |
-webkit-transform-origin: 0 0; | |
-moz-transform-origin: 0 0; | |
} | |
} | |
input:checked + label { | |
background: #77E371; | |
&:before { | |
transform: translateX(26px); | |
-webkit-transform: translateX(26px); | |
-moz-transform: translateX(26px); | |
animation: check 0.3s ease-out; | |
-webkit-animation: check 0.3s ease-out; | |
-moz-animation: check 0.3s ease-out; | |
transform-origin: 100% 0; | |
-webkit-transform-origin: 100% 0; | |
-moz-transform-origin: 100% 0; | |
} | |
} | |
} | |
@keyframes uncheck { | |
0% { | |
transform: translateX(26px); | |
} | |
20% { | |
transform: translateX(13px) scaleX(1.5); | |
} | |
40% { | |
transform: translateX(0px) scaleX(0.75); | |
} | |
70% { | |
transform: translateX(6px) scaleX(1); | |
} | |
100% { | |
transform: translateX(0px); | |
} | |
} | |
@-webkit-keyframes uncheck { | |
0% { | |
-webkit-transform: translateX(26px); | |
} | |
20% { | |
-webkit-transform: translateX(13px) scaleX(1.5); | |
} | |
40% { | |
-webkit-transform: translateX(0px) scaleX(0.75); | |
} | |
70% { | |
-webkit-transform: translateX(6px) scaleX(1); | |
} | |
100% { | |
-webkit-transform: translateX(0px); | |
} | |
} | |
@-moz-keyframes uncheck { | |
0% { | |
-moz-transform: translateX(26px); | |
} | |
20% { | |
-moz-transform: translateX(13px) scaleX(1.5); | |
} | |
40% { | |
-moz-transform: translateX(0px) scaleX(0.75); | |
} | |
70% { | |
-moz-transform: translateX(6px) scaleX(1); | |
} | |
100% { | |
-moz-transform: translateX(0px); | |
} | |
} | |
@keyframes check { | |
0% { | |
transform: translateX(2px); | |
} | |
20% { | |
transform: translateX(13px) scaleX(1.5); | |
} | |
40% { | |
transform: translateX(26px) scaleX(0.75); | |
} | |
70% { | |
transform: translateX(20px) scaleX(1); | |
} | |
100% { | |
transform: translateX(26px); | |
} | |
} | |
@-webkit-keyframes check { | |
0% { | |
-webkit-transform: translateX(2px); | |
} | |
20% { | |
-webkit-transform: translateX(13px) scaleX(1.5); | |
} | |
40% { | |
-webkit-transform: translateX(26px) scaleX(0.75); | |
} | |
70% { | |
-webkit-transform: translateX(20px) scaleX(1); | |
} | |
100% { | |
-webkit-transform: translateX(26px); | |
} | |
} | |
@-moz-keyframes check { | |
0% { | |
-moz-transform: translateX(2px); | |
} | |
20% { | |
-moz-transform: translateX(13px) scaleX(1.5); | |
} | |
40% { | |
-moz-transform: translateX(26px) scaleX(0.75); | |
} | |
70% { | |
-moz-transform: translateX(20px) scaleX(1); | |
} | |
100% { | |
-moz-transform: translateX(26px); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment