Disable bounce on first and last item in Owl Carousel

1.4k views Asked by At

I'm using a Owl Carousel slider.

When you reach the last or first item of the slider you can still drag the slider although there aren't anymore items. Instead there is a bounce effect like when you pull down a native mobile app to refresh the content.

Demo: (link removed since the official docs aren't there anymore) Drag the slider to the right and it will bounce back.

Is there a possibility to disable that bounce effect?

1

There are 1 answers

0
Alberto I.N.J. On BEST ANSWER

Yes, you can disable the bounce effect. I struggled finding it but I did it.

Just remove or comment out this lines code in owl.carousel.js:

base.newPosX = Math.max(Math.min(base.newPosX, minSwipe()), maxSwipe());
if (base.browser.support3d === true) {
    base.transition3d(base.newPosX);
} else {
    base.css2move(base.newPosX);
}


E.g.

owl.carousel.js

function dragMove(event) {
    var ev = event.originalEvent || event || window.event,
    minSwipe,
    maxSwipe;

    base.newPosX = getTouches(ev).x - locals.offsetX;
    base.newPosY = getTouches(ev).y - locals.offsetY;
    base.newRelativeX = base.newPosX - locals.relativePos;

    if (typeof base.options.startDragging === "function" && locals.dragging !== true && base.newRelativeX !== 0) {
        locals.dragging = true;
        base.options.startDragging.apply(base, [base.$elem]);
    }

    if ((base.newRelativeX > 8 || base.newRelativeX < -8) && (base.browser.isTouch === true)) {
        if (ev.preventDefault !== undefined) {
            ev.preventDefault();
        } else {
            ev.returnValue = false;
        }
        locals.sliding = true;
    }

    if ((base.newPosY > 10 || base.newPosY < -10) && locals.sliding === false) {
        $(document).off("touchmove.owl");
    }

    minSwipe = function () {
        return base.newRelativeX / 5;
    };

    maxSwipe = function () {
        return base.maximumPixels + base.newRelativeX / 5;
    };

    // base.newPosX = Math.max(Math.min(base.newPosX, minSwipe()), maxSwipe());
    // if (base.browser.support3d === true) {
    //     base.transition3d(base.newPosX);
    // } else {
    //     base.css2move(base.newPosX);
    // }
}


Hope it helps.