Synchro
Synchro

Reputation: 1269

Swiper slider: slide change to other div

I have created a parallax slider but I have one big problem with changing the slider. I can change the slider when my mouse is inside the blue zone

enter image description here

As you could understand the blue zone (or the blue block) is the swiper-wrapper class, I can set the height to 100%, but in this case my layout is destroyed.

I want to know if swiper-slider provides me with such a property so that I can change the slider outside the blue zone (or outside the swiper-wrapper)?

Upvotes: 0

Views: 4411

Answers (1)

Ezra Siton
Ezra Siton

Reputation: 7741

If you want to create some space inside each slide add extra div inside swiper slide. **it is better to use % and not px for the space.

Snippet example:

const swiper = new Swiper('.swiper', {
  // Optional parameters
  loop: false,
  centeredSlidesBounds: true,
  slidesPerView: 2.1,
  spaceBetween: 20,
  // If we need pagination
  pagination: {
    el: '.swiper-pagination',
  },

  // Navigation arrows
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  }
});
.swiper {
  width: 100%;
  height: 100%;
}

.card_inside_swiper{
  background: red;
  max-width: 90%;
  margin:  0px auto;
}
<link
      rel="stylesheet"
      href="https://unpkg.com/swiper@8/swiper-bundle.min.css"
      />

<style>
.swiper-slide {
  background: #2196f3;
  height: auto;
}
</style>

<!-- Slider main container -->
<div class="swiper">
  <!-- Additional required wrapper -->
  <div class="swiper-wrapper">
    <!-- Slides -->
    <div class="swiper-slide" data-city="london"><div class="card_inside_swiper"><p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

</p></div></div>
    <div class="swiper-slide" data-city="london"><div class="card_inside_swiper"><p>hello</p></div></div>
    <div class="swiper-slide" data-city="london"><div class="card_inside_swiper"><p>hello</p></div></div>
    ...
  </div>
  <!-- If we need pagination -->
  <div class="swiper-pagination"></div>

  <!-- If we need navigation buttons -->
  <div class="swiper-button-prev"></div>
  <div class="swiper-button-next"></div>

</div>

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

Upvotes: 1

Related Questions