M
M
Mr. Smith2018-03-20 03:46:16
JavaScript
Mr. Smith, 2018-03-20 03:46:16

How to adjust the next/prev buttons to the modified Owl Carousel 2 script?

The usual Owl Carousel 2, with not much changes, added this piece to determine the location of the active element and automatically start from it when the page loads

var poWidth = $(".owl-item").width(); // Узнаем ширину одного элемента
            var poWidthBlock = $(".owl-wrapper-outer").width(); // Узнаем ширину внешнего блока
            var poAll = $(".owl-item").length; // Всего элементов в каруселе
             var poPrev = $("#inside").prevAll().length; // Количество элементов перед выбранным

             var poResultMax = poWidth * poAll - poWidthBlock + 1; // Максимальное расстояние
             var poResult = poWidth * poPrev; // Расстояние к активному элементу

            if (poResult <= poResultMax) {
              var poRes = poResult;
            } else {
               var poRes = poResultMax;
            }

            base.$elem.find(".owl-wrapper").css("display", "block");
            base.$elem.find(".owl-wrapper").css("transform", "translate3d(-" + poRes + "px, 0px, 0px)"); // Результат


With a touch, and mice if you drag everything works fine from an active place. But the prev/next buttons don't want to start from there, they start from the first element. How to solve such a question? " Full situation on JSFiddle "

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mr. Smith, 2018-03-20
@MrSS

Jupiter Max , Chet does not work this function. But thanks for suggesting the direction, and the answer will be this code

$(document).ready(function() {
    var owl = $("#owl-serial").owlCarousel({
        items : 4,
        itemsDesktop : [1199,3],
        itemsDesktopSmall : [979,3]

    });

     var poPrev = $("#inside").prevAll().length; // Номер нужного слайда

    // Now move the carousel to the third item.
    owl = $("#owl-serial").data('owlCarousel');
    owl.jumpTo(poPrev);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question