A
A
Alexey Klyonin2019-08-19 15:30:18
JavaScript
Alexey Klyonin, 2019-08-19 15:30:18

How to display the correct number of slides in OwlCarousel2 with loop enabled?

Good afternoon.
The site has an output of 5 slides implemented on Owl carousel 2 It is
necessary to output the number of the current slide and the total number of slides.
The documentation has an example of how this can be done, but the problem is that with loop:true, the number of slides in the DOM increases due to clones, which, as I understand it, are created specifically for the loop.
The question is how can I display the actual number of slides and their correct numbers?
Suggestions to disable loop and use rewind instead of the first one don't work. It is necessary that the cycle works and the number of slides is correctly displayed.
The current call code is:

var reviewsSlider = $("#reviews-slider");
  reviewsSlider.owlCarousel({
      items: 1,
      loop: true,
      margin: 35,
      center: false,
      autoplay: true,
      dots: false,
      navText: [
          '<i class="fa fa-angle-left"></i>',
          '<i class="fa fa-angle-right"></i>'
      ]
  });

  $('.reviews__slide-controls__left').click(function() {
      reviewsSlider.trigger('prev.owl.carousel');
  })

  $('.reviews__slide-controls__right').click(function() {
      reviewsSlider.trigger('next.owl.carousel');
  })
  reviewsSlider.on('changed.owl.carousel', function(event){
    $('.slide-controls-number__active').text(++event.item.index)
    $('.slide-controls-number__total').text(event.item.count)
  });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Bogomazov, 2019-08-19
@Aleks7487

https://codepen.io/maer2k/pen/qPVWEd
https://codepen.io/codeninja93/pen/AXadWQ

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question