A Pen by Tiffany Brown on CodePen.
Created
August 9, 2015 05:18
-
-
Save webinista/da84d94f51dbc6dcc270 to your computer and use it in GitHub Desktop.
Using input[type=range] to create toggles
This file contains hidden or 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
| <h1>Using <code>input[type=range]</code> to create toggles</h1> | |
| <p> | |
| <input type="range" value="0" min="0" max="1" step="1"> | |
| </p> |
This file contains hidden or 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
| var range = document.querySelectorAll('[type=range]'); | |
| [].map.call(range, function(r) { | |
| r.addEventListener('change', function(e) { | |
| e.target.classList.toggle('active'); | |
| }); | |
| }); |
This file contains hidden or 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{ | |
| font: 200 24px / 1 sans-serif; | |
| } | |
| h1 { | |
| font-size: 1em; | |
| font-weight: inherit; | |
| } | |
| [type=range] { | |
| -webkit-appearance: none; | |
| -moz-appearance: none; | |
| background: #aaa; | |
| border-radius: 10px; | |
| border: 1px solid transparent; | |
| box-shadow: none; | |
| display: block; | |
| padding: 2px; | |
| vertical-align: bottom; | |
| width: 50px; | |
| transition: all 100ms linear; | |
| /* Scaling changes the size without needing to adjust CSS proportions. But you may also need to translate in one or both directions */ | |
| transform: scale(2) translateX(30%); | |
| } | |
| [type=range]::-webkit-slider-thumb { | |
| -webkit-appearance: none; | |
| height: 1em; | |
| width: 1em; | |
| border: 0; | |
| background-color: #fff; | |
| border-radius: 1000px; | |
| border: 0; | |
| } | |
| [type=range]::-moz-range-thumb { | |
| width: .9rem; | |
| height: .9rem; | |
| border: 0; | |
| border-radius: 100px; | |
| background-color: #fff; | |
| } | |
| [type=range]::-moz-range-track { | |
| background: transparent; | |
| } | |
| [type=range]::-ms-track { | |
| cursor: pointer; | |
| background: transparent; | |
| border-color: transparent; | |
| color: transparent; | |
| } | |
| [type=range]::-ms-thumb { | |
| width: 10px; | |
| height: 10px; | |
| border-radius: 10px; | |
| background: #fff; | |
| border: 1px solid #fff; | |
| } | |
| [type=range].active { | |
| background: #4caf50; | |
| } | |
| [type=range]::-ms-track, | |
| [type=range]::-ms-fill-lower, | |
| [type=range]::-ms-fill-upper { | |
| background: transparent; | |
| } | |
| [type=range]:focus { | |
| outline: none; | |
| border-color: #f50; | |
| } | |
| [type=range]::-ms-tooltip { | |
| display: none; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment