I have twenty elements (input checkboxes) on the page. I need an object (button) to appear when clicking on any of the elements . But when no element is active, the object needs to disappear. Please help me to do this. I thought for a long time, but did not find a solution. Here is the HTML code for convenience:
.submit-btn {
opacity: 0;
position: absolute;
left: 50%;
top: 75%;
transform: translate(-50%, 0);
width: 147px;
height: 52px;
background: #fff;
border: 3px solid #21ebff;
box-sizing: border-box;
border-radius: 30px;
cursor: pointer;
background: linear-gradient(to right, #21ebff 0%, #21ebff 50%, #ffffff 50%, #ffffff 100%);
background-size: 200% 100%;
background-position: 100% 0;
transition: background-position 0.5s;
transition: all 0.3s ease-in-out;
}
.submit-btn:hover {
background-position: 0 0;
}
.arrow {
display: inline-flex;
position: relative;
width: 0;
height: 20px;
cursor: pointer;
margin-top: 5px;
}
.active {
opacity: 1;
}
.arrow:before,
.arrow:after {
display: inline-flex;
position: absolute;
content: '';
}
.arrow:before {
top: 8px;
right: -50px;
width: 40px;
height: 3px;
background-color: #21ebff;
transition: all 0.6s;
}
.arrow:after {
width: 15px;
height: 15px;
top: 2px;
right: -51px;
border-top: 3px solid #21ebff;
border-right: 3px solid #21ebff;
transform: rotate(45deg);
transition: all 0.5s;
}
.submit-btn:hover .arrow:before {
background-color: #fff;
}
.submit-btn:hover .arrow:after {
border-top: 3px solid #fff;
border-right: 3px solid #fff;
}
.decades-checkbox-list {
position: absolute;
top: 35%;
left: 50%;
transition: all 2s;
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
.decades-checkbox-col {
display: flex;
flex-direction: column;
margin: 0 40px;
}
.decades-checkbox-item {
width: 300px;
margin: 15px 0;
display: flex;
align-items: center;
user-select: none;
}
.decades-checkbox-item {
width: 300px;
margin: 15px 0;
display: flex;
align-items: center;
user-select: none;
}
.decades-checkbox-input:checked .decades-checkbox-span {
border-color: #21ebff;
box-shadow: 0px 0px 0px 15px #21ebff inset;
}
.decades-checkbox-input:checked .decades-checkbox-span::after {
opacity: 1;
transform: scale(1);
}
.decades-checkbox-label {
padding-left: 40px;
word-spacing: 3px;
font-family: 'Marvel';
font-size: 26px;
color: #202020;
position: absolute;
z-index: 10;
cursor: pointer;
}
.decades-checkbox-span {
width: 25px;
height: 25px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
border-radius: 100px;
background-color: #FFF;
border: 3px solid #21ebff;
box-shadow: 0px 0px 0px 0px #21ebff inset;
transition: all 0.15s cubic-bezier(0, 1.05, 0.72, 1.07);
}
.decades-checkbox-span::after {
content: '';
width: 100%;
height: 100%;
opacity: 0;
z-index: 4;
position: absolute;
transform: scale(0);
background-size: 50%;
background-image: url('https://s6.picofile.com/d/8392306668/bacc888c-bed7-41a9-bf24-f6ff0718f471/checkmark.svg');
background-repeat: no-repeat;
background-position: center;
transition-delay: 0.2s !important;
transition: all 0.25s cubic-bezier(0, 1.05, 0.72, 1.07);
}
<ul >
<div >
<li >
<input type="checkbox" id="decadesCboxInput-1" onclick="disableFunc()">
<span ></span>
<label for="decadesCboxInput-1">The 1930s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-2" onclick="disableFunc()">
<span ></span>
<label for="decadesCboxInput-2">The 1940s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-3" onclick="disableFunc()">
<span ></span>
<label for="decadesCboxInput-3">The 1950s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-4" onclick="disableFunc()">
<span ></span>
<label for="decadesCboxInput-4">The 1960s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-5" onclick="disableFunc()">
<span ></span>
<label for="decadesCboxInput-5">The 1970s</label>
</li>
</div>
<div >
<li >
<input type="checkbox" id="decadesCboxInput-6" onclick="disableFunc()">
<span ></span>
<label for="decadesCboxInput-6">The 1980s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-7" onclick="disableFunc()">
<span ></span>
<label for="decadesCboxInput-7">The 1990s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-8" onclick="disableFunc()">
<span ></span>
<label for="decadesCboxInput-8">The 2000s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-9" onclick="disableFunc()">
<span ></span>
<label for="decadesCboxInput-9">The 2010s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-10" onclick="disableFunc()">
<span ></span>
<label for="decadesCboxInput-10">The 2020s</label>
</li>
</div>
</ul>
CodePudding user response:
function disableFunc(){
....
if(document.querySelectorAll("input[type=checkbox]:checked").length===0){
disableButton();
}else{
enableButton();
}
}
CodePudding user response:
Please delegate, then you can remove all the inline disableFunc
I assume the button has the ID of buttonID
const container = document.querySelector(".decades-checkbox-list")
container.addEventListener("click", function(e) {
document.getElementById("buttonID").hidden = container.querySelectorAll("input[type=checkbox]:checked").length===0
})
CodePudding user response:
$('.decades-checkbox-list').on('click', '.decades-checkbox-item [type="checkbox"]', function(){
if($(this).is(":checked")){
$('.btnSubmit').show();
}else{
$('.btnSubmit').hide();
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul >
<div >
<li >
<input type="checkbox" id="decadesCboxInput-1">
<span ></span>
<label for="decadesCboxInput-1">The 1930s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-2">
<span ></span>
<label for="decadesCboxInput-2">The 1940s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-3">
<span ></span>
<label for="decadesCboxInput-3">The 1950s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-4">
<span ></span>
<label for="decadesCboxInput-4">The 1960s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-5">
<span ></span>
<label for="decadesCboxInput-5">The 1970s</label>
</li>
</div>
<div >
<li >
<input type="checkbox" id="decadesCboxInput-6">
<span ></span>
<label for="decadesCboxInput-6">The 1980s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-7">
<span ></span>
<label for="decadesCboxInput-7">The 1990s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-8">
<span ></span>
<label for="decadesCboxInput-8">The 2000s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-9">
<span ></span>
<label for="decadesCboxInput-9">The 2010s</label>
</li>
<li >
<input type="checkbox" id="decadesCboxInput-10">
<span ></span>
<label for="decadesCboxInput-10">The 2020s</label>
</li>
</div>
</ul>
<input type="button" name="submit-btn" value="Submit" style="display: none" >
CodePudding user response:
You can use below code:
if ($('input[type=checkbox]').is(":checked")) {
//any one is checked (show button in your case)
}
else {
//hide button
}