Last active
December 29, 2015 04:59
-
-
Save arvindang/7619073 to your computer and use it in GitHub Desktop.
Three way toggle
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-git2.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<!-- <a href="#"> | |
<img class="static" src="http://placekitten.com/100/100" alt=""> | |
</a> | |
--> | |
<input type="checkbox" id="checkbox"> | |
<label for="checkbox"><img src="http://placekitten.com/100/100" alt=""></label> | |
</body> | |
</html> |
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
img { | |
border-radius: 50%; | |
border: 4px solid transparent; | |
} | |
input[type=checkbox] { | |
display: none; | |
} | |
.static { | |
border: 4px solid transparent; | |
} | |
.absent { | |
border: 4px solid red; | |
} | |
.tardy { | |
border: 4px solid blue; | |
} |
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 $check = $("input[type=checkbox]"), el; | |
$check | |
.data('checked',0) | |
.click(function(e) { | |
el = $(this); | |
switch(el.data('checked')) { | |
// unchecked, going indeterminate | |
case 0: | |
el.data('checked',1); | |
el.prop('indeterminate',true); | |
$('img').addClass('tardy'); | |
break; | |
// indeterminate, going checked | |
case 1: | |
el.data('checked',2); | |
el.prop('indeterminate',false); | |
el.prop('checked',true); | |
$('img').removeClass('tardy'); | |
$('img').addClass('absent'); | |
break; | |
// checked, going unchecked | |
default: | |
el.data('checked',0); | |
el.prop('indeterminate',false); | |
el.prop('checked',false); | |
$('img').removeClass('absent'); | |
$('img').addClass('static'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Three way toggle state using a checkboxes.