Insanus
@Insanus

Почему в swiper js не работают меттоды observer, observeParents, observeSlideChildren?

Спрятал я слайдер состоящий из одного скрола в меню в итоге если при первом открытие меню даные методы не срабатоваю, а при последующих теряется drag.

<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.css" />

<header class="header" id="header">
    <div class="container header__container">
        <button class="burger btn__modal header__burger" data-id="header">
            <span class="burger__line"></span>
            <span class="burger__line"></span>
            <span class="burger__line"></span>
        </button>

    </div>
    <div class="header__slider swiper-container scrollbar">
        <div class="swiper-wrapper header__wrapper" style="min-width: 0; min-height: 0;">
            <nav class="menu swiper-slide">
                <ul class="menu__list ">
              
                    <li class="menu__item">
                        <a href="#" class="link menu__link">Полезные ресурсы</a>
                    </li>
                </ul>
            </nav>
        </div>
        <div class="swiper-scrollbar"></div>
    </div>
</header>

<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>


.sprite {
  display: none;
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100px;
  height: 100vh;
  background-color: #e7e7f6;
  z-index: 20;
  box-shadow: 0px 0px 4px rgba(11, 11, 29, 0.1);
}
.header__container {
  padding: 60px 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
}
.header__logo {
  width: 70px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.header__slider {
  padding: 0 50px;
  background-color: #e7e7f6;
  border-left: 1px solid rgba(11, 11, 29, 0.2);
  height: 0;
  font-size: 24px;
  position: fixed;
  top: 0;
  left: 100px;
  width: auto;
  overflow: hidden;
  transition: height 0.6s 0s;
  pointer-events: none;
}
.modal--active .header__slider {
  height: 100vh;
  pointer-events: visible;
}

.burger {
  width: 60px;
  height: 16px;
  background-color: transparent;
  position: relative;
  border: none;
}
.modal--active .burger {
  height: 43px;
}
.burger__line {
  position: absolute;
  bottom: 0;
  left: 0;
  width: inherit;
  height: 1px;
  background-color: #0b0b1d;
  pointer-events: none;
  transition: all 0.5s 0s;
}
.burger__line:first-child {
  top: 50%;
}
.burger__line:last-child {
  top: 0;
}
.modal--active .burger__line {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg);
}
.modal--active .burger__line:last-child {
  transform: translate(-50%, -50%) rotate(45deg);
}

.sistem {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.sistem__item {
  margin-bottom: 10px;
  width: 50px;
  height: 50px;
}
.sistem__item:last-child {
  margin-bottom: 0;
}
.sistem__link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: rgba(11, 11, 29, 0);
}
.sistem__link:hover, .sistem__link:focus {
  background-color: rgba(11, 11, 29, 0.13);
}
.sistem__link:active {
  opacity: 0.5;
}
.sistem__icon {
  height: 30px;
  width: 30px;
  fill: #0b0b1d;
}

.menu {
  padding: 60px 0;
  height: auto;
}
.menu__list {
  min-width: 0;
  flex-direction: column;
}
.menu__item {
  margin-bottom: 40px;
}
.menu__item:last-child {
  margin-bottom: 0;
}
.menu__link {
  color: inherit;
  background-image: linear-gradient(#0b0b1d 50%, #0b0b1d 50%);
}
.menu__accordion {
  max-width: 380px;
}
.menu__wrapp {
  font-size: 20px;
}
.link__list .link__item {
  margin-bottom: 20px;
}
.link__list .link__item:last-child {
  margin-bottom: 0;
}


let body = document.body,
    modal;


new Swiper('.scrollbar', {
    direction: 'vertical',
    slidesPerView: 'auto',
    freeMode: true,
    scrollbar: {
        el: '.swiper-scrollbar',
        draggable: true,
    },
    mousewheel: true,
    watchOverflow: true,

    observer: true,
    observeParents: true,
    observeSlideChildren: true,
});

window.addEventListener('click', e => {
    let target = e.target;

    if (target.closest('.btn__modal')) {
        modal = document.querySelector(`#${target.closest('.btn__modal').dataset.id}`);
        switchModals();
    }

});

let switchModals = () => {
    modal.classList.toggle('modal--active');
    body.classList.toggle('modal--active');
}
  • Вопрос задан
  • 27 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы