swiper no scroll

Change class name on click in jQuery

by avgustre

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/js/swiper.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/css/swiper.css">
<section id="sect1">
  lorem
</section>

<div class="swiper-container">
  <div class="swiper-wrapper">
    <div class="swiper-slide">Slide 1</div>
    <div class="swiper-slide">Slide 2</div>
    <div class="swiper-slide">Slide 3</div>
    <div class="swiper-slide">Slide 4</div>
  </div>
</div>


<section id="sect3">
  ipsum
</section>

<div id="foo"></div>
<div id="foo2"></div>

CSS

body,
html {
  height: 100%;
  background: grey;
}

.swiper-container,
.swiper-wrapper,
.swiper-slide {
  width: 100%;
  height: 500px;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;
  /* Center slide text vertically */
  display: flex;
  justify-content: center;
  align-items: center;
}

.swiper-slide:nth-child(1) {
  background: #D8E2DC;
}

.swiper-slide:nth-child(2) {
  background: #FFE5D9;
}

.swiper-slide:nth-child(3) {
  background: #FFCAD4;
}

.swiper-slide:nth-child(4) {
  background: #F4ACB7;
}

section {
  backgroud: #23422;
  height: 400px;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#foo {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1000;
}

#foo2 {
  position: fixed;
  top: 30px;
  right: 0;
  z-index: 1000;
}

JavaScript

var swiper = new Swiper('.swiper-container', {
  direction: 'vertical',

  mousewheel: {
    releaseOnEdges: true
  },
  slidesPerView: 1,
  on: {
    slideChange: function() {
      if ((mySwiper.activeIndex != 0) && (mySwiper.activeIndex != 8)) {
        $('body').addClass('no_scroll')
      } else {
        $('body').removeClass('no_scroll')
      }
    }
  },
});


$(window).bind('wheel', function(e) {
  if (e.originalEvent.wheelDelta > 0) {
    $("#foo").text("up");
  } else {
    $("#foo").text("down");
  }
});