splide icon indicating copy to clipboard operation
splide copied to clipboard

Issue with decimal perPage

Open JbIPS opened this issue 5 years ago • 12 comments

Hi,

I tried to use perPage: 2.5 in my slider. Visually, it works very well and arrows works perfectly. But the issue starts when dragging the slider. For a reason I can't understand, the slider rewind to the first slide when the drag/touch starts (but rewind is not true in my config).

Here's my config:

  new Splide('.splide', {
    pagination: false,
    perPage: 2.5,
    perMove: 1,
    rewind: false,
    breakpoints: {
      900: {
        perPage: 1.3,
      }
    }
  }).mount();

Could you point me to the general direction of the code that might cause this issue?

Thank you

JbIPS avatar Feb 11 '21 10:02 JbIPS

Alright, I found the culprit in the getSlide function which returns undefined when given a decimal number.

Flooring the index do the trick but any reason you're not simply doing return Slides[index] instead of a .filter()?

JbIPS avatar Feb 11 '21 16:02 JbIPS

Just out of curiosity, why do you want two and a half slides to appear per page?

johnson-jd avatar Feb 12 '21 00:02 johnson-jd

To show users there is more content (my arrows are hidden)

JbIPS avatar Feb 12 '21 08:02 JbIPS

You might be best using the padding option which allows some of the next slide to be seen.

https://splidejs.com/options/#padding

habitualshaker avatar Feb 12 '21 10:02 habitualshaker

Close the issue due to the major version update. Feel free to create a new issue or open a new discussion.


As habitualshaker says (thanks!), use the padding option. The perPage option must be an integer, otherwise the slider will be broken.

NaotoshiFujita avatar Oct 09 '21 16:10 NaotoshiFujita

You might be best using the padding option which allows some of the next slide to be seen.

https://splidejs.com/options/#padding

the link should be https://splidejs.com/guides/options/#padding

vallerydelexy avatar Jul 21 '23 06:07 vallerydelexy

@NaotoshiFujita the problem I'm having with this solution is that the padding shows once you reach the end of the slider. Ideally, in the attached screenshot, the last slide would sit flush against the right side of the container, with no padding.

The goal of this use case is to peek the next slide, not to add padding to the slider. Is there a cleaner solution to this? Thanks

Screenshot 2023-10-12 at 3 56 25 PM

jclarkdev avatar Oct 12 '23 19:10 jclarkdev

@NaotoshiFujita the problem I'm having with this solution is that the padding shows once you reach the end of the slider. Ideally, in the attached screenshot, the last slide would sit flush against the right side of the container, with no padding.

The goal of this use case is to peek the next slide, not to add padding to the slider. Is there a cleaner solution to this? Thanks

Screenshot 2023-10-12 at 3 56 25 PM

Would also like to know a great solution for this. Also to centre the slides would be great.

WarboxLiam avatar Jun 12 '24 10:06 WarboxLiam

<Splide
  options={{
  type: "slide",
  perPage: 2,
  gap: "2rem",
  pagination: false,
  arrows: true,
  padding: { right: "15%" },
}}>

razvanFrandes avatar Sep 09 '24 08:09 razvanFrandes

Use Padding right on .splide__track not on splide__slide

xgrid-ayoubkhan558 avatar Sep 29 '25 08:09 xgrid-ayoubkhan558

@jclarkdev did you find a solution to this? i'm struggling to figure this out now.

wheeleran avatar Jan 19 '26 15:01 wheeleran

@jclarkdev did you find a solution to this? i'm struggling to figure this out now.

@wheeleran I use a different slider library now. Without a proper fix for this issue, it requires you to do a lot of reworking/hacky CSS to achieve the intended outcome.

jclarkdev avatar Jan 30 '26 18:01 jclarkdev