Created
May 27, 2017 17:10
-
-
Save Arfey/929504a9bc8e1c0fcea22474874e1a63 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<input id="all" type="checkbox"> | |
<input id="man" type="checkbox"> | |
<input id="woman" type="checkbox"> | |
<script> | |
jQuery.fn.extend({ | |
ann: function() { | |
let $newCheckbox = $('<div>', {'class': 'checkbox'}) | |
let $this = $(this) | |
$this.hide(); // hide origin element | |
print = $this.after($newCheckbox) | |
$newCheckbox.click(function() { | |
$(this).toggleClass('active'); | |
}) | |
return $newCheckbox | |
} | |
}); | |
$all = $('#all').ann(); // activate plagin | |
$man = $('#man').ann(); // activate plagin | |
$woman = $('#woman').ann(); // activate plagin | |
function checkActive() { | |
setTimeout(function() { | |
[$man, $woman].map((obj) => { | |
if (obj.hasClass('active')) { | |
$all.removeClass('active') | |
return | |
} | |
}) | |
}, 0) | |
} | |
function checkAll() { | |
[$man, $woman].map((obj) => { | |
obj.addClass('active') | |
}) | |
} | |
$man.click(checkActive) | |
$woman.click(checkActive) | |
$all.click(checkAll) | |
</script> | |
<style> | |
.checkbox { | |
width: 10px; | |
height: 10px; | |
border: 1px solid; | |
background: white; | |
transition: all .3s ease-out | |
} | |
.checkbox.active { | |
border: 1px solid green; | |
background: green; | |
} | |
</style> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment