Splidejs / splide

Splide is a lightweight, flexible and accessible slider/carousel written in TypeScript. No dependencies, no Lighthouse errors.
https://splidejs.com
MIT License
4.83k stars 418 forks source link

Cannot scroll without animation #1299

Open bonstio opened 5 months ago

bonstio commented 5 months ago

Checks

Version

v4.1.3

Description

It's not possible to call scroll without invoking an animation.

Reproduction Link

No response

Steps to Reproduce

  1. Setup Splide
  2. Make a call (e.g. from the JavaScript Console) to

    splide.Components.Scroll.scroll(index, 0, true);

Since the duration param here is set to 0, there should NOT be a visible animation, yet there is.

The problem happens because of this line of code in Scroll.ts

duration = noDistance ? 0 : duration || max( abs( destination - from ) / BASE_VELOCITY, MIN_DURATION );

One fix is to explicitly check if duration has been defined:

   duration = noDistance ?
        0 : 
        (duration === undefined ? 
            max(abs(destination - from) / BASE_VELOCITY, MIN_DURATION) :
            duration);

Expected Behaviour

No scroll animation