cubiq/SwipeView

When "loop: false", pulling and releasing past the bounds, restores to position instantaneously

Opened this issue · 3 comments

On iPad, with "loop: false", when you drag past the first or last page and release your finger, the page instantly snaps back instead of smoothly animating back to its position.

The native swiper does smoothly animate back to its position, so it looks rather odd in an app.

I fixed it by changing this code in _end()

        // Check if we exceeded the snap threshold
        if (dist < this.snapThreshold) {
            this.slider.style[transitionDuration] = Math.floor(300 * dist / this.snapThreshold) + 'ms';
            this.__pos(-this.page * this.pageWidth);
            return;
        }

to:

        // Check if we exceeded the snap threshold
        if (dist < this.snapThreshold) {
            this.slider.style[transitionDuration] = 400 + 'ms';
            this.__pos(-this.page * this.pageWidth);
            return;
        }

Indeed, it happens because a couple of lines before dist is set to 0. If you want to keep the original formula, you can replace dist with Math.abs(point.pageX - this.startX) and it should work.

its realy nice resolve