@Serdev21
Middle Front-end developer

Как убрать обрезание последнего слайда в Owl Carousel Vue,js?

Здравствуйте, есть слайдер сделанный с помощью Owl Carousel под Vue.js и по какой-то причине последний видимый слайд в нем обрезается по ширине, как я понял что ширина всех слайдов неправильно высчитывается но не понимаю почему? Вот код самого компонента
<template>
  <div class="gallery__wrap">
    <carousel
      :items="1"
      :dots="false"
      :nav="false"
      :loop="false"
      :autoHeight="false"
      :margin="0"
      @changed="changed"
      :responsive="{768:{items: visibleItemsCount,margin: 40}}"
    >
      <div class="gallery__item" :class="{ 'gallery__item--offset-left': itemClassOffset }" v-for="(image, index) in images" :key="index">
        <a href="#" class="gallery__link" @click.prevent="showPopup(image)">
          <img
            :data-src="image.src"
            :alt="alt"
            class="lozad gallery__img"
          />
        </a>
      </div>
    </carousel>
    <div class="custom-nav small" v-if="images.length > 1">
      <div class="custom-nav__prev" @click="prev">
        <svg
          width="17"
          height="9"
          viewBox="0 0 17 9"
          fill="none"
          xmlns="http://www.w3.org/2000/svg"
        >
          <path
            d="M16.9913 4.57239L13.4689 0.987061V3.67606L0.259766 3.67606L0.259766 5.46873L13.4689 5.46873V8.15773L16.9913 4.57239Z"
            fill="#EEEEEE"
          />
        </svg>
      </div>
      <div class="custom-nav__next" @click="next" v-if="images.length > 1">
        <svg
          width="17"
          height="9"
          viewBox="0 0 17 9"
          fill="none"
          xmlns="http://www.w3.org/2000/svg"
        >
          <path
            d="M16.9913 4.57239L13.4689 0.987061V3.67606L0.259766 3.67606L0.259766 5.46873L13.4689 5.46873V8.15773L16.9913 4.57239Z"
            fill="#EEEEEE"
          />
        </svg>
      </div>
      <div class="custom-nav__line">
        <div class="progress" :style="progress"></div>
      </div>
    </div>
    <doctorPhoto :images="images" :visible="isVisible" :index="imageId" @closed="isVisible = false" />
  </div>
</template>

<script>
import carousel from "vue-owl-carousel";
import doctorPhoto from "./doctor-photo";

export default {
  name: "gallery-photo",
  components: {
    carousel,
    doctorPhoto
  },
  props: {
    images: {
      type: Array,
      required: true
    },
    alt: {
      type: String,
      required: false
    }
  },
  methods: {
    changed(data) {
      if ( window.matchMedia("(max-width: 767px)").matches ) {
        this.currentStep = data.item.index + 1;
      }

       else if ( window.matchMedia("(min-width: 1500px)").matches ) {
            this.currentStep = data.item.index + 4;
        }

       else {
        this.currentStep = data.item.index + 3;
      }
    },

    next() {
      document.querySelector(this.parent + " .owl-next").click();
    },
    prev() {
      document.querySelector(this.parent + " .owl-prev").click();
    },
    showPopup(image) {
      this.imageId = image.index;
      this.isVisible = !this.isVisible;
    }
  },
  computed: {
    countOfSlides() {
      return this.images.length;
    },

    oneStep() {
      return 100 / this.countOfSlides;
    },

    width() {
      return this.currentStep * this.oneStep;
    },

    progress() {
      return "width: " + this.width + "%;";
    },
      visibleItemsCount() {
          if (window.matchMedia("(min-width: 1500px)").matches) {
              return 4;
          } else {
              return 3;
          }
      },
      itemClassOffset() {
        return window.matchMedia("(min-width: 1500px)").matches && this.countOfSlides <= 3 ? true : false;
      }
  },

  mounted: function() {
    for (let i = 0; i < this.images.length; i++) {
      this.images[i].index = i;
    }
    this.parent = "#" + this.$el.parentElement.id;
  },

  data: () => ({
    isVisible: false,
    currentStep: (window.matchMedia("(max-width: 767px)").matches == true) ? 1 : (window.matchMedia("(min-width: 1500px)").matches == true) ? 4 : 3,
    imageId: 1
  })
};
</script>

<style>
.owl-carousel {
  overflow: hidden;
}
</style>


и вот как выглядит сам слайдер обрезанный
6002d7f95d344575815265.png
  • Вопрос задан
  • 129 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

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