vincent15000's avatar

Splide with a rolling window of 21 items

Hello,

It's a project with Laravel and VueJS.

I'm using Splide to display a carousel.

To avoid to have too many requests, I'd like to load a window around the central item displayed on the screen. For example if I display the first item among 33, I want to display item 1 and also load the 10 previous and 10 next items. As it's the first one to display, I will load the items from 24 to 33, item 1 and then items from 2 to 11.

And to avoid to load for example 500 items, the idea is to have in memory only a maximum of 21 items (10 before + 1 displayed + 10 after).

Here is the code of the controller.

And the one of the front.

It works quite fine except one thing : as a new set of items is loaded, it generates a little shake while adding and removing some items.

slider.value?.splide.go(newIndex + 5); // or - 5

If I only add new items without removing any (so the items count grows), I don't have any problem. But I'd like to avoid having 500 items loaded. So I want to limit the number of loaded items to 21.

Do you have any idea how to avoid this little shake ?

Thanks for your help.

V

0 likes
0 replies

Please or to participate in this conversation.