slick icon indicating copy to clipboard operation
slick copied to clipboard

Left translate is wrong when centerMode is true and there is only one slide

Open stevevg opened this issue 10 years ago • 7 comments

When centerMode is on, and I have only one slide, and slidesToShow = 1, the slide is translated to the left, but I have no way to move it to the center.

Issue happens both using slick 1.4.1 and 1.5.5

Following is the code (cut to just show the "interesting" part)

                $('#offerte-home').slick({
                    autoplay: true,
                    autoplaySpeed: 5000,
                    slidesToShow: 3,
                    dots: true,
                    arrows: false,
                        responsive: [
                            {
                                breakpoint: 480,
                                settings: {
                                    arrows: false,
                                    centerMode: true,
                                    centerPadding: '40px',
                                    slidesToShow: 1,
                                    /*infinite: false,*/
                                    autoplay: false
                                }
                            }
                        ]
                });

The following image shows what happens (left) vs. the expected behavior (right).

slick_issue

The problem seems to reside in the .slick-track CSS, which reports

transform: translate3d(-220px, 0px, 0px);

while the expected would be

transform: translate3d(0px, 0px, 0px);

stevevg avatar May 20 '15 09:05 stevevg

I found the same problem, when carousel is empty and I try to add slides using slickAdd(...) Looks like calculation for _.slideOffset in below lines are wrong https://github.com/kenwheeler/slick/blob/master/slick/slick.js#L1037-L1038

_.slideOffset is used to set targetLeft, which in turn used to set x co-ordinate for translate3d(..) https://github.com/kenwheeler/slick/blob/master/slick/slick.js#L1625

Thanks, Vinni

vinamrajais avatar May 20 '15 11:05 vinamrajais

I modified the calculation to _.slideOffset += .slideWidth * Math.floor((.options.slidesToShow + 1) / 2) - _.slideWidth;

This make the first slide to center align while adding through slickAdd.

In centerMode there are + 1 slide (half left and half right), so shouldn't it adds + 1 while calculating? @kenwheeler please comment.

Thanks, Vinni

vinamrajais avatar May 20 '15 11:05 vinamrajais

Here is fiddle to display the center alignment issue http://jsfiddle.net/Vinni/444usgku/

Add slides one by one, 1st slide will start from left but not center. After 6th slide is added all slides will be centered.

vinamrajais avatar May 20 '15 14:05 vinamrajais

Nice fiddle!

simeydotme avatar May 20 '15 17:05 simeydotme

Thanks, I leverage it from http://kenwheeler.github.io/slick/ source code. :) If you agree with issue, can you label this as 'bug'.

vinamrajais avatar May 21 '15 06:05 vinamrajais

Hi there I've been experiencing the exact same issue but it works if I roll back to v1.6.0

lexcode avatar Sep 25 '17 09:09 lexcode

This issue is still open in 2024 😢

alvindera97 avatar Apr 10 '24 01:04 alvindera97