Как сделать так, чтобы если хоть один из элементов активен, то появлялся объект, а если ни один не активен - исчезала
У меня есть список из десяти элементов (checkbox). Мне нужно, чтобы при нажатии на любой из элементов появлялся объект (кнопка) и также исчезало взаимодействие с другим элементом (тоже checkbox, но в другом стиле), однако если ни один из элементов не активен, нужно чтобы объект (кнопка) исчезал, а взаимодействие с другим элементом различного стиля снова становилось возможным. И наоборот, если элемент, который в другом стиле, активен, то взаимодействие со списком из десяти элементов становилось невозможным, а кнопка появлялась. Помогите, пожалуйста, справиться с этим. Долго думал над решением, но ничего не сработало. Если что-то в условии не понятно, то пишите, с радостью объясню еще раз. Вот HTML-код для удобства:
<ul class="decades-checkbox-list">
<div class="decades-checkbox-col">
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-1">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-1">The 1930s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-2">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-2">The 1940s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-3">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-3">The 1950s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-4">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-4">The 1960s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-5">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-5">The 1970s</label>
</li>
</div>
<div class="decades-checkbox-col">
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-6">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-6">The 1980s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-7">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-7">The 1990s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-8">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-8">The 2000s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-9">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-9">The 2010s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-10">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-10">The 2020s</label>
</li>
</div>
<div class="skip-checkbox decades-skip-checkbox">
<input class="skip-checkbox-input" id="decadesSkipCboxInput" type="checkbox">
<label class="skip-checkbox-label" for="decadesSkipCboxInput">
<svg class="skip-checkbox-svg decades-skip-checkbox-svg" width="18px" height="18px" viewBox="0 0 18 18">
<path
d="M1,9 L1,3.5 C1,2 2,1 3.5,1 L14.5,1 C16,1 17,2 17,3.5 L17,14.5 C17,16 16,17 14.5,17 L3.5,17 C2,17 1,16 1,14.5 L1,9 Z">
</path>
<polyline points="1 9 7 14 15 4"></polyline>
</svg>
<span class="skip-checkbox-span decades-skip-checkbox-span">The time doesn't really matter.</span>
</label>
</div>
</ul>
<button class="submit-btn" id="submitBtn">
<div class="arrow"></div>
</button>
CSS-код:
/* Decades Checkbox List */
.decades-checkbox-list {
position: absolute;
top: 0;
left: 50%;
transform: translate(-40%, 0);
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-input {
opacity: 0;
visibility: hidden;
position: absolute;
}
.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);
}
.decades-skip-checkbox {
width: 100%;
position: absolute;
left: 50%;
top: 100%;
}
.decades-skip-checkbox-input {
display: none;
}
/* Skip chechbox */
.skip-checkbox {
margin-top: 60px;
position: relative;
left: 50%;
transform: translate(-30%, 0);
}
.skip-checkbox-input {
display: none;
}
.skip-checkbox-label {
cursor: pointer;
position: relative;
margin: auto;
width: 18px;
height: 18px;
-webkit-tap-highlight-color: transparent;
-webkit-user-select: none;
user-select: none;
transform: translate3d(0, 0, 0);
}
.skip-checkbox-label:before {
content: "";
position: absolute;
top: -15px;
left: -15px;
width: 48px;
height: 48px;
border-radius: 50%;
background: rgba(#223254, .03);
opacity: 0;
transition: opacity .2s ease;
}
.skip-checkbox-label:after {
content: "";
position: absolute;
top: -15px;
left: -15px;
width: 48px;
height: 48px;
border-radius: 50%;
background: rgba(#223254, .03);
opacity: 0;
transition: opacity .2s ease;
}
svg {
position: relative;
z-index: 1;
fill: none;
stroke-linecap: round;
stroke-linejoin: round;
stroke: #C8CCD4;
stroke-width: 1.5;
transform: translate3d(0, 0, 0);
transition: all .2s ease;
}
path {
stroke-dasharray: 60;
stroke-dashoffset: 0;
}
polyline {
stroke-dasharray: 22;
stroke-dashoffset: 66;
}
polyline:hover,
polyline:before polyline:after {
opacity: 1;
}
svg {
stroke: #21ebff;
}
.skip-checkbox-input:checked+.skip-checkbox-label svg {
stroke: #21ebff;
}
.skip-checkbox-input:checked+.skip-checkbox-label path {
stroke-dashoffset: 60;
transition: all .3s linear;
}
.skip-checkbox-input:checked+.skip-checkbox-label polyline {
stroke-dashoffset: 42;
transition: all .2s linear;
transition-delay: .15s;
}
.skip-checkbox-span {
margin-left: 7px;
-webkit-user-select: none;
user-select: none;
font-family: 'Marvel', sans-serif;
font-size: 26px;
color: #202020;
}
/* Submit Btn */
.submit-btn {
margin-top: 120px;
position: absolute;
left: 50%;
top: 100%;
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;
}
Ответы (1 шт):
<div class="decades-checkbox-list">
<div class="decades-checkbox-wrap">
<ul class="decades-checkbox-col">
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-1">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-1">The 1930s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-2">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-2">The 1940s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-3">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-3">The 1950s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-4">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-4">The 1960s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-5">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-5">The 1970s</label>
</li>
</ul>
<ul class="decades-checkbox-col">
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-6">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-6">The 1980s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-7">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-7">The 1990s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-8">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-8">The 2000s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-9">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-9">The 2010s</label>
</li>
<li class="decades-checkbox-item">
<input class="decades-checkbox-input" type="checkbox" id="decadesCboxInput-10">
<span class="decades-checkbox-span"></span>
<label class="decades-checkbox-label" for="decadesCboxInput-10">The 2020s</label>
</li>
</ul>
</div>
<div class="skip-checkbox">
<input class="skip-checkbox-input" id="decadesSkipCboxInput" type="checkbox">
<label class="skip-checkbox-label" for="decadesSkipCboxInput">
<svg class="skip-checkbox-svg" width="18px" height="18px" viewBox="0 0 18 18">
<path
d="M1,9 L1,3.5 C1,2 2,1 3.5,1 L14.5,1 C16,1 17,2 17,3.5 L17,14.5 C17,16 16,17 14.5,17 L3.5,17 C2,17 1,16 1,14.5 L1,9 Z">
</path>
<polyline points="1 9 7 14 15 4"></polyline>
</svg>
<span class="skip-checkbox-span">The time doesn't really matter.</span>
</label>
</div>
</div>
<button class="submit-btn" id="submitBtn">
<span class="arrow"></span>
</button>
body {
text-align: center;
}
/* Decades Checkbox List */
.decades-checkbox-wrap,
.decades-checkbox-list {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
.decades-checkbox-wrap {
width: 100%;
}
.decades-checkbox-col {
display: flex;
flex-direction: column;
padding: 0;
margin: 0;
list-style: none;
}
.decades-checkbox-item {
margin: 15px 0;
display: flex;
position: relative;
}
.decades-checkbox-input {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
border: 0;
clip: rect(0 0 0 0);
}
.decades-checkbox-input:checked + .decades-checkbox-span {
border-color: #21ebff;
box-shadow: 0 0 0 15px #21ebff inset;
}
.decades-checkbox-input:checked + .decades-checkbox-span::after {
opacity: 1;
transform: scale(1);
}
.decades-checkbox-label {
padding-left: 50px;
word-spacing: 3px;
font-family: 'Marvel';
font-size: 26px;
color: #202020;
cursor: pointer;
}
.decades-checkbox-span {
width: 25px;
height: 25px;
display: flex;
justify-content: center;
align-items: center;
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);
cursor: pointer;
position: absolute;
z-index: -1;
}
.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);
}
.decades-skip-checkbox-input {
display: none;
}
/* Skip chechbox */
.skip-checkbox {
margin-top: 60px;
position: relative;
width: 100%;
text-align: center;
}
.skip-checkbox-input {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
border: 0;
clip: rect(0 0 0 0);
}
.skip-checkbox-label {
cursor: pointer;
position: relative;
margin: auto;
width: 18px;
height: 18px;
-webkit-tap-highlight-color: transparent;
-webkit-user-select: none;
user-select: none;
transform: translate3d(0, 0, 0);
}
.skip-checkbox-label:before {
content: "";
position: absolute;
top: -15px;
left: -15px;
width: 48px;
height: 48px;
border-radius: 50%;
background: #223254;
opacity: 0;
transition: opacity .2s ease;
}
.skip-checkbox-label:after {
content: "";
position: absolute;
top: -15px;
left: -15px;
width: 48px;
height: 48px;
border-radius: 50%;
background: #223254;
opacity: 0;
transition: opacity .2s ease;
}
svg {
position: relative;
z-index: 1;
fill: none;
stroke-linecap: round;
stroke-linejoin: round;
stroke: #C8CCD4;
stroke-width: 1.5;
transform: translate3d(0, 0, 0);
transition: all .2s ease;
}
path {
stroke-dasharray: 60;
stroke-dashoffset: 0;
}
polyline {
stroke-dasharray: 22;
stroke-dashoffset: 66;
}
polyline:hover,
polyline:before polyline:after {
opacity: 1;
}
svg {
stroke: #21ebff;
}
.skip-checkbox-input:checked + .skip-checkbox-label svg {
stroke: #21ebff;
}
.skip-checkbox-input:checked + .skip-checkbox-label path {
stroke-dashoffset: 60;
transition: all .3s linear;
}
.skip-checkbox-input:checked + .skip-checkbox-label polyline {
stroke-dashoffset: 42;
transition: all .2s linear;
transition-delay: .15s;
}
.skip-checkbox-span {
margin-left: 7px;
-webkit-user-select: none;
user-select: none;
font-family: 'Marvel', sans-serif;
font-size: 26px;
color: #202020;
}
.disabled {
opacity: 0.3;
}
.disabled {
pointer-events: none;
}
/* Submit Btn */
.submit-btn {
margin-top: 120px;
width: 0;
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;
opacity: 0;
pointer-events: none;
overflow: hidden;
}
.submit-btn.show {
pointer-events: auto;
opacity: 1;
width: 147px;
}
.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;
}
document.addEventListener('DOMContentLoaded', function() {
const checkboxLists = document.querySelector('.decades-checkbox-wrap');
const decadesInputs = checkboxLists.querySelectorAll('.decades-checkbox-input');
const skip = document.querySelector('.skip-checkbox');
const skipCheckbox = skip.querySelector('.skip-checkbox-input');
const submitBtn = document.querySelector('.submit-btn');
checkboxLists.addEventListener('click', function(e) {
for (let i = 0; i < decadesInputs.length; i++) {
if(decadesInputs[i].checked) {
skip.classList.add('disabled');
submitBtn.classList.add('show');
break;
} else {
skip.classList.remove('disabled');
submitBtn.classList.remove('show');
}
}
});
skip.addEventListener('click', function(e) {
if (skipCheckbox.checked) {
checkboxLists.classList.add('disabled');
submitBtn.classList.add('show');
} else {
checkboxLists.classList.remove('disabled');
submitBtn.classList.remove('show');
}
});
});
Если я правильно понял)