question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Offset calculation when slideCount == slidesToShow

See original GitHub issue

Hi Ken,

First of all thanks for this superb plugin, really appreciated!

I ran into problems with v1.3.15 (v1.4 and v1.4.1 don’t seem to fix it either), when my SlideCount was equal to SlidesToShow (and CenterMode = true and Infinite = true). In this case it was showing only 4 out of 5 slides because on the left a extra margin was added with translate3D.

When looking through your code i found the problem in the getLeft() function.

if (_.slideCount <= _.options.slidesToShow){
            _.slideOffset = 0;
            verticalOffset = 0;
}

Ok, so now the slideOffset = 0;

if (_.options.centerMode === true && _.options.infinite === true) {
            _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2) - _.slideWidth;
        } else if (_.options.centerMode === true) {
            _.slideOffset = 0;
            _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2);
}

So now the slider gets added 1 slideWidth as Offset on the left side, ergo: showing 4 of 5 slides (last one is “hidden”), while this should be no Offset.

Is this something you can fix for upcomming versions?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
danodmcommented, Jun 17, 2015

I’ve managed to modify the getLeft() function so that it calculates and centres correctly based on whether slideCount is less than or equal to slidesToShow.

on line 1037 I modified the if statement from

if (_.options.centerMode === true && _.options.infinite === true) {
     _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2) - _.slideWidth;
} else if (_.options.centerMode === true) {
    _.slideOffset = 0;
    _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2);
}

to

if (_.options.centerMode === true && _.options.infinite === true) {
    if (_.slideCount <= _.options.slidesToShow) {
        _.slideOffset = ((_.slideWidth * Math.floor(_.options.slidesToShow)) / 2) - ((_.slideWidth * _.slideCount) / 2);
    } else {
         _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2) - _.slideWidth;
    }
} else if (_.options.centerMode === true) {
   _.slideOffset = 0;
   _.slideOffset += _.slideWidth * Math.floor(_.options.slidesToShow / 2);
}

Now the behaviour of the slide is as follows.

If slideCount is less than or equal to slideToShow centre the overall width of all items, else centre to the currently active slide.

2reactions
leggomuhgreggocommented, Sep 16, 2016

Fixed in #2118.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Offset calculation when slideCount == slidesToShow - Drupal
The slider appears to be off-center and only shows one item. It sounds a common issue with the lack of slide amount compared...
Read more >
Slick Slider Starting With A Left Offset - ADocLib
I have a problem with the slider when the view filter is set to a date greater than double post #2489358: Offset calculation...
Read more >
Slick slider starting with a left offset - Stack Overflow
I am working on a template which is bootstrap based. I need to set up a full width slick slider, but its initial...
Read more >
Swiper API
Add (in px) additional slide offset in the end of the container (after all slides) ... Enable this feature to calculate each slides...
Read more >
Center mode slick slider. you can add this to your SCSS file to ...
centerMode: true, centerPadding: '50px', slidesToShow: 3, dots: true, ... 2015 Offset calculation when slideCount == slidesToShow kenwheeler closed this as ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found