A Pen by Luis Miguel F. on CodePen.
Last active
September 15, 2015 17:47
-
-
Save lmfresneda/389648664a2c34264a6b to your computer and use it in GitHub Desktop.
Coverage HTML+CSS+JS
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
<div id="lope-wrapper" class="lope-coverage"> | |
<span></span> | |
<span></span> | |
<span></span> | |
<span></span> | |
</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
//num = 0 | 1 | 2 | 3 | 4 | |
//if num > 4, num = 4 | |
//if num < 0, num = 0 | |
function changeCoverage(idWrapper, num){ | |
num = num < 0 ? 0 : num > 4 ? 4 : parseInt(num); | |
var wrapper = document.getElementById(idWrapper); | |
var spans = wrapper.getElementsByTagName("span"); | |
for(var k = 0; k < spans.length; k++){ | |
spans[k].classList.remove("lope-coverage-on"); | |
} | |
for(var k = 0; k < num; k++){ | |
spans[k].classList.add("lope-coverage-on"); | |
} | |
} | |
//cambiamos la cobertura a 2 para probar | |
changeCoverage("lope-wrapper", 2); |
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
.lope-coverage{ | |
width: 20px; | |
height: 18px; | |
font-size: 1px; | |
} | |
.lope-coverage span{ | |
margin: 2%; | |
border: 1px solid #898888; | |
width: 10%; | |
height: 87%; | |
display: inline-block; | |
} | |
.lope-coverage span:nth-child(1){ | |
height: 22%; | |
} | |
.lope-coverage span:nth-child(2){ | |
height: 44%; | |
} | |
.lope-coverage span:nth-child(3){ | |
height: 67%; | |
} | |
.lope-coverage-on{ | |
background-color: #898888; | |
border: 1px solid #898888 !important; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment