Заменить содержимое, а не только текст - PullRequest
0 голосов
/ 27 мая 2020

Для кода я хочу, чтобы ползунок непрозрачности был рядом с записанным выделением, а затем отображался текст при выборе. Однако ползунок не отображается, только текст диапазона. Наряду с этим я немного смущен, как я могу связать div с источниками данных, чтобы при выборе текст отображался. Как я могу это сделать?

$('#contrast').on('input', function() {
    $('.section1').css('opacity', $(this).val());
});

for (const dropdown of document.querySelectorAll(".custom-select-wrapper")) {
    dropdown.addEventListener('click', function () {
        this.querySelector('.custom-select').classList.toggle('open');
    })
}

for (const option of document.querySelectorAll(".custom-option")) {
    option.addEventListener('click', function () {
        if (!this.classList.contains('selected')) {
            this.parentNode.querySelector('.custom-option.selected').classList.remove('selected');
            this.classList.add('selected');
            // this.closest('.custom-select').querySelector('.custom-select__trigger').textContent = this.textContent;
            this.closest('.custom-select').querySelector('.custom-select__trigger').append(this);
        }
    })
}

window.addEventListener('click', function (e) {
    for (const select of document.querySelectorAll('.custom-select')) {
        if (!select.contains(e.target)) {
            select.classList.remove('open');
        }
    }
});

<div class="section1">Test opacity..</div>




    <div class="container">
        <div class="custom-select-wrapper">
            <div class="custom-select">
                <div class="custom-select__trigger"><span>selection1</span>
                    <div class="arrow"></div>
                </div>
                <div class="custom-options">
                    <span class="custom-option selected" data-value="tesla">selection1
                        <input id="contrast" class="slider" type="range"  max="1" min="0" step="0.01" value="1"/></span>
                    <span class="custom-option" data-value="volvo">selection2
                        <input id="2" class="slider" type="range"  max="1" min="0" step="0.01" value="1"/></span>
                    <span class="custom-option" data-value="mercedes">selection3
                        <input id="3" class="slider" type="range"  max="1" min="0" step="0.01" value="1"/></span>
                </div>
            </div>
        </div>
    </div>

*,
*:after,
*:before {
  box-sizing: border-box;
}


.test{
  background-color: pink;
  width: 500px;
}

.section1{
  height: 100px;
  width: 100px;
  background-color: red;
}

.container {
  margin: 20px;
  max-width: 300px;
}

.custom-select-wrapper {
  position: relative;
  user-select: none;
  width: 500px;
}

.custom-select {
  display: flex;
  flex-direction: column;
  border-width: 0 2px 0 2px;
  border-style: solid;
  border-color: #394a6d;
}

.custom-select__trigger {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  font-size: 20px;
  font-weight: 300;
  color: #3b3b3b;
  height: 60px;
  line-height: 60px;
  background: #ffffff;
  cursor: pointer;
  border-width: 2px 0 2px 0;
  border-style: solid;
  border-color: #394a6d;
}

.custom-options {
  position: absolute;
  display: block;
  top: 100%;
  left: 0;
  right: 0;
  border: 2px solid #394a6d;
  border-top: 0;
  background: #fff;
  transition: all 0.5s;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 2;
}

.custom-select.open .custom-options {
  opacity: 1;
  visibility: visible;
  pointer-events: all;
}

.custom-option {
  position: relative;
  display: block;
  padding: 0 22px 0 22px;
  font-size: 22px;
  font-weight: 300;
  color: #3b3b3b;
  line-height: 60px;
  cursor: pointer;
  transition: all 0.5s;
}

.custom-option:hover {
  cursor: pointer;
  background-color: #b2b2b2;
}

.custom-option.selected {
  color: #ffffff;
  background-color: #305c91;
}

.arrow {
  position: relative;
  height: 15px;
  width: 15px;
}

.arrow::before,
.arrow::after {
  content: "";
  position: absolute;
  bottom: 0px;
  width: 0.15rem;
  height: 100%;
  transition: all 0.5s;
}

.arrow::before {
  left: -5px;
  transform: rotate(45deg);
  background-color: #394a6d;
}

.arrow::after {
  left: 5px;
  transform: rotate(-45deg);
  background-color: #394a6d;
}

.open .arrow::before {
  left: -5px;
  transform: rotate(-45deg);
}

.open .arrow::after {
  left: 5px;
  transform: rotate(45deg);
}

...