<div class="dropdown">
<div class="dropdown__select"></div>
<ul class="dropdown__list">
<li>
<div class="dropdown__list-left">
<div class="dropdown__list-title">Взрослые</div>
<div class="dropdown__list-subtitle">старше 12 лет</div>
</div>
<div class="dropdown__amount">
<div class="dropdown__amount-minus">–</div>
<div class="dropdown__amount-number">0</div>
<div class="dropdown__amount-plus">+</div>
</div>
</li>
<li>
<div class="dropdown__list-left">
<div class="dropdown__list-title">Дети</div>
<div class="dropdown__list-subtitle">2-12 лет</div>
</div>
<div class="dropdown__amount">
<div class="dropdown__amount-minus">–</div>
<div class="dropdown__amount-number">0</div>
<div class="dropdown__amount-plus">+</div>
</div>
</li>
<li>
<div class="dropdown__list-left">
<div class="dropdown__list-title">Младенцы</div>
<div class="dropdown__list-subtitle">до 2 лет, без места</div>
</div>
<div class="dropdown__list-right">
<div class="dropdown__amount">
<div class="dropdown__amount-minus">–</div>
<div class="dropdown__amount-number">0</div>
<div class="dropdown__amount-plus">+</div>
</div>
</div>
</li>
<li>
<div class="checkbox">
<input id="business" type="checkbox">
<label for="business">Перелёт бизнес классом</label>
</div>
</li>
</ul>
</div>
*, *:before, *:after {
box-sizing: border-box;
}
body {
margin: 30px;
font-family: 'Roboto', sans-serif;
font-weight: 300;
}
.dropdown {
position: relative;
max-width: 300px;
}
.dropdown__select {
border: 1px solid #1ec7c2;
border-radius: 5px;
padding: 15px 20px 15px 15px;
color: #e9eaec;
font-size: 13px;
position: relative;
cursor: pointer;
user-select: none;
}
.dropdown__select:after {
content: "";
display: block;
border: solid #496885;
border-width: 0 2px 2px 0;
padding: 3px;
position: absolute;
right: 15px;
top: 17px;
transform: rotate(-135deg);
transition: all 0.5s;
}
.dropdown__select.active:after {
transform: rotate(45deg);
top: 15px;
}
.dropdown__list {
display: none;
background-color: #142d4c;
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: auto;
max-height: 300px;
margin-top: 5px;
border-radius: 5px;
overflow-y: auto;
padding: 20px;
}
.dropdown__list.active {
display: block;
}
.dropdown__list > li {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 5px;
color: #fff;
}
.dropdown__list-title {
font-size: 14px;
color: #d3d1df;
}
.dropdown__list-subtitle {
font-size: 12px;
color: #3b5674;
padding: 5px 0;
}
.dropdown__amount {
display: flex;
justify-content: space-between;
}
.dropdown__amount-minus,
.dropdown__amount-plus {
border: 1px solid #1ec7c2;
color: #1ec7c2;
border-radius: 50%;
width: 25px;
height: 25px;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
line-height: 0.5;
transition: all 0.5s;
cursor: pointer;
user-select: none;
}
.dropdown__amount-minus:hover,
.dropdown__amount-plus:hover {
background-color: #1ec7c2;
color: #fff;
}
.dropdown__amount-number {
padding: 0 10px;
display: flex;
align-items: center;
justify-content: center;
min-width: 40px;
user-select: none;
}
.checkbox {
position: relative;
margin: 0;
text-align: left;
}
.checkbox label {
cursor: pointer;
display: inline;
line-height: 1.25em;
vertical-align: top;
clear: both;
padding-left: 1px;
font-size: 13px;
color: #d3d1df;
user-select: none;
}
.checkbox label:not(:empty) {
padding-left: 0.75em;
}
.checkbox label:before, .checkbox label:after {
content: "";
position: absolute;
left: 0;
top: 0;
}
.checkbox label:before {
width: 1.25em;
height: 1.25em;
border: 1px solid rgba(255, 255, 255, 0.54);
border-radius: 0.325em;
cursor: pointer;
transition: background .3s;
}
.checkbox input[type="checkbox"] {
outline: 0;
visibility: hidden;
width: 1.25em;
margin: 0;
display: block;
float: left;
font-size: inherit;
}
.checkbox input[type="checkbox"]:checked + label:before {
background: #1ec7c2;
border: none;
}
.checkbox input[type="checkbox"]:checked + label:after {
transform: translate(0.25em, 0.3365384615em) rotate(-45deg);
width: 0.75em;
height: 0.375em;
border: 0.125em solid #fff;
border-top-style: none;
border-right-style: none;
}
.checkbox input[type="checkbox"]:disabled + label:before {
border-color: rgba(255, 255, 255, 0.26);
}
.checkbox input[type="checkbox"]:disabled:checked + label:before {
background: rgba(255, 255, 255, 0.26);
}
$(document).ready(function() {
$(".dropdown__select").on("click", function() {
$(this).toggleClass("active");
$(".dropdown__list").slideToggle();
});
$(".dropdown__amount-minus").on("click", function() {
var i = $(this)
.siblings(".dropdown__amount-number")
.text();
if (i > 0) {
$(this)
.siblings(".dropdown__amount-number")
.text(--i);
}
count();
});
$(".dropdown__amount-plus").on("click", function() {
var i = $(this)
.siblings(".dropdown__amount-number")
.text();
$(this)
.siblings(".dropdown__amount-number")
.text(++i);
count();
});
$(".checkbox").on("click", function() {
count();
});
function count() {
var count = $(".dropdown__amount-number");
var amount = 0;
count.each(function(i, el) {amount += +$(el).text();});
if ($("#business").is(":checked")) {
$(".dropdown__select").text(amount + " " + declOfNum(amount, ["пассажир", "пассажира", "пассажиров"]) + ", Бизнес класс");
} else {
$(".dropdown__select").text(amount + " " + declOfNum(amount, ["пассажир", "пассажира", "пассажиров"]) + ", Эконом");
}
}
function declOfNum(number, titles) {
cases = [2, 0, 1, 1, 1, 2];
return titles[
number % 100 > 4 && number % 100 < 20
? 2
: cases[number % 10 < 5 ? number % 10 : 5]
];
}
count();
});