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.

Miscalculated width of slides track on variableWidth with progressive lazy load

See original GitHub issue

Hi Ken, First of all - great plugin, fantastic work, respect!

However, with the new feature “variableWidth” combined with progressive lazy load and centerMode, I encountered problems when having higher amount of image slides in the slick (ca 100+).

The width of “slick-track” element on first few calls to setDimensions seems to be miscalculated - track is slightly shorter than it should be, as the images while initializing do not give correct slide width to the slick.

The effect of this issue is fairly bad: slide-track expands for two rows (as the fully loaded images can not fit within miscalculated track width).

After while (when all progressive images are fully initialized), all is getting back OK, f.e. after first slide change all gets finally calculated correctly and slick is looking fine.

I did not have a time to dive deeper in your code, so i just created kind a dirty hack to fix it (see bellow), but I think this issue shall be addressed and get resolved more elegant way.

The merit of my hack is simple:

  1. it simply checks the slick-track width on every call to setDimensions, and compares previously calculated width with the newly calculated. if it differs (width changes as the lazy loading images still continue initializing), it sets the track width manually for INSANE value, e.g. 500000 (to surely accommodate all slides).

  2. Once slick-track width stabilizes (previously calculated width equals to new), all returns to normal and manually setting the insane width is bypassed. Track has correct width, and looks good.

As the process is quite quick, the hack does not have any bad influence on initial display, the slick simply starts “fixed” as it would normally, but it is really dirty hack. 😉

THE HACK

First, I created new var for storing the slick-track width (at line ca 144): _.lastTrackWidth = 0;

Than, I modified the setDimensions method, inside >variableWidth === true< condition (line ca 1335):

    } else if (_.options.variableWidth === true) {
        var trackWidth = 0;

        // *** edit
        // *** HACK for miscalculated track width while progressive lazyLoad (wrong slide widths)
        if (_.options.lazyLoad == "progressive" && _.$slideTrack.width() !== _.lastTrackWidth ) {
            trackWidth = 500000;
        }
        // *** END edit

        _.slideWidth = Math.ceil(_.listWidth / _.options.slidesToShow);
        _.$slideTrack.children('.slick-slide').each(function(idx){
            trackWidth += Math.ceil($(this).outerWidth(true));
        });
        _.$slideTrack.width(Math.ceil(trackWidth) + 1);

        // *** edit
        // *** HACK for miscalculated track width while progressive lazyLoad (wrong slide widths)
        _.lastTrackWidth = Math.ceil(trackWidth) + 1;
        // *** END edit

    } else {

Please, I am sure you will have better idea, and I hope in a mean time the above may help somebody to resolve this issue in a dirty way, before fixed in source.

Thanks

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:92 (25 by maintainers)

github_iconTop GitHub Comments

3reactions
larzillacommented, Jul 2, 2015

I was having this same issue. My fix was similar to @alvinpascoe. One of the parent elements was set to display:table. Once I changed this parent to display:block, the issue was solved.

1reaction
virtualcommented, Jan 22, 2015

Thanks @chrisdatlas, adding the min-width of 100% to .slick-track worked for me; now they aren’t stacking small images anymore

Read more comments on GitHub >

github_iconTop Results From Across the Web

variableWidth doesn't display right [#2490528] | Drupal.org
I've done my slick slideshow with thumbslider described here ... works fine, because the next image is not displayed due the lazy load....
Read more >
Slick Slider Width 0 On Initial Page Load - Stack Overflow
I'm running into a really weird issue with a Slick Slider. Sometimes, on the very first page load the slide and track width...
Read more >
kenwheeler/slick - Gitter
I'm using it in a web project and just wanted to know what the recommended image size of a slide should be if...
Read more >
slick - the last carousel you'll ever need - Ken Wheeler
To use lazy loading, set a data-lazy attribute // on your img tags and leave off the src <img ... variableWidth, boolean, false,...
Read more >
react-slick | Yarn - Package Manager
implemented pauseOnDotsHover property; implemented Progressive LazyLoad property, lazyLoad is now ondemand/progressive; implemented lazyloadError event ...
Read more >

github_iconTop Related Medium Post

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