Last active
August 29, 2015 14:20
-
-
Save gunnarbittersmann/2693e2cdf9efd8deaf9d to your computer and use it in GitHub Desktop.
keyboard (div)
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
| /** | |
| * keyboard (div) | |
| * http://forum.selfhtml.org/self/2015/may/03/indexwert-von-array-element-ermitteln/1639259#m1639259 | |
| */ | |
| .keyboard | |
| { | |
| display: -webkit-inline-flex; | |
| display: inline-flex; | |
| } | |
| .keyboard label | |
| { | |
| border: 1px solid black; | |
| width: 2em; | |
| height: 6em; | |
| background: ivory; | |
| } | |
| .keyboard label.ebony | |
| { | |
| position: absolute; | |
| width: 1.2em; | |
| height: 4em; | |
| margin-left: -0.6em; | |
| background: black; | |
| } | |
| .keyboard label.selected | |
| { | |
| background: green; | |
| } | |
| .keyboard label:has(input:checked) | |
| { | |
| background: red; | |
| } | |
| .keyboard input | |
| { | |
| visibility: hidden; | |
| } |
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
| <form> | |
| <div class="keyboard" lang="de"> | |
| <label class="ivory" aria-label="C"><input type="radio" name="note" value="12"/></label> | |
| <label class="ebony" aria-label="Cis/Des"><input type="radio" name="note" value="13"/></label> | |
| <label class="ivory" aria-label="D"><input type="radio" name="note" value="14"/></label> | |
| <label class="ebony" aria-label="Dis/Es"><input type="radio" name="note" value="15"/></label> | |
| <label class="ivory" aria-label="E"><input type="radio" name="note" value="16"/></label> | |
| <label class="ivory" aria-label="F"><input type="radio" name="note" value="17"/></label> | |
| <label class="ebony" aria-label="Fis/Ges"><input type="radio" name="note" value="18"/></label> | |
| <label class="ivory" aria-label="G"><input type="radio" name="note" value="19"/></label> | |
| <label class="ebony" aria-label="Gis/As"><input type="radio" name="note" value="20"/></label> | |
| <label class="ivory" aria-label="A"><input type="radio" name="note" value="21"/></label> | |
| <label class="ebony" aria-label="Ais/B"><input type="radio" name="note" value="22"/></label> | |
| <label class="ivory" aria-label="H"><input type="radio" name="note" value="23"/></label> | |
| <label class="ivory" aria-label="c"><input type="radio" name="note" value="24"/></label> | |
| <label class="ebony" aria-label="cis/des"><input type="radio" name="note" value="25"/></label> | |
| <label class="ivory" aria-label="d"><input type="radio" name="note" value="26"/></label> | |
| <label class="ebony" aria-label="dis/es"><input type="radio" name="note" value="27"/></label> | |
| <label class="ivory" aria-label="e"><input type="radio" name="note" value="28"/></label> | |
| </div> | |
| <button>OK</button> | |
| </form> |
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 keyboardLabelElements = document.querySelectorAll('.keyboard label'), | |
| previousKeyboardLabelElement; | |
| for (var i = 0, l = keyboardLabelElements.length; i < l; i++) | |
| { | |
| keyboardLabelElements[i].addEventListener('click', function () | |
| { | |
| if (previousKeyboardLabelElement && previousKeyboardLabelElement !== this) | |
| { | |
| previousKeyboardLabelElement.classList.remove('selected'); | |
| } | |
| this.classList.add('selected'); | |
| previousKeyboardLabelElement = this; | |
| }, false); | |
| } |
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
| {"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment