最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Slick.js smooth transition between first and last elements - Stack Overflow

programmeradmin0浏览0评论

I'm trying to create a sliding gallery using Slick.js - look at the "Center Mode" part.

All in all the gallery functions correctly, however I have a small glitch: when I'm on the last element and scrolling to the first - I'm not getting a smooth transition, but rather a small jump of the first element.

I created a Codepen to demonstrate what I'm talking about:

I tried to modify any possible class or classes bination:

.slick-cloned, .slick-active etc...

But I'm still getting this jump. How can I fix it?

I'm trying to create a sliding gallery using Slick.js - look at the "Center Mode" part.

All in all the gallery functions correctly, however I have a small glitch: when I'm on the last element and scrolling to the first - I'm not getting a smooth transition, but rather a small jump of the first element.

I created a Codepen to demonstrate what I'm talking about: https://codepen.io/anon/pen/YLExjo

I tried to modify any possible class or classes bination:

.slick-cloned, .slick-active etc...

But I'm still getting this jump. How can I fix it?

Share Improve this question asked May 7, 2018 at 13:16 IgalIgal 6,10321 gold badges84 silver badges139 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

Slick has a somewhat strange behaviour regarding classes that it adds to or removes from elements "on the edges" of the slideshow. One approach to fix that problem is to add an event handler and fix the classes by yourself:

$('.your-selector').slick({
    // configuration
}).on('beforeChange', (event, slick, currentSlide, nextSlide) => {
    if (currentSlide !== nextSlide) {
        document.querySelectorAll('.slick-center + .slick-cloned').forEach((next) => {
            // timeout required or Slick will overwrite the classes
            setTimeout(() => next.classList.add('slick-current', 'slick-center'));
        });
    }
});

Essentially, it will enforce the next (or previous) element in the slideshow to actually have the slick-center class that you set the transition on.

See https://codepen.io/anon/pen/KRyXrG for a demo.

I know this question is old but I'm having the same issue, and didn't find. Anything that helped

发布评论

评论列表(0)

  1. 暂无评论