slick icon indicating copy to clipboard operation
slick copied to clipboard

Variable Width + Infinite

Open picard102 opened this issue 9 years ago • 193 comments

When using variable width there is an amount of white space generated at either end.

When scrolling right as you approach the last slide more and more whitespace opens up until you hit the very last slide, at which point the white space is replaced by previous slides in infinite mode.

Similarly, if you move left through the slider, content disappears and is replaced by white space.

I would think that the expected results would be the white space be occupied by slides as the end comes into view, rather than as the last slide hits the left edge.

http://jsfiddle.net/memvovkz/

picard102 avatar Apr 06 '15 16:04 picard102

+1 to this issue

jDavidnet avatar Apr 08 '15 15:04 jDavidnet

+1

marlosirapuan avatar Apr 14 '15 00:04 marlosirapuan

+1

onstuimig avatar Apr 15 '15 09:04 onstuimig

+1

midudev avatar Apr 20 '15 22:04 midudev

+1 Very true...feelsbuggy. This should really be an option/setting.

nexflo avatar Apr 21 '15 11:04 nexflo

+1

mafrost avatar May 04 '15 12:05 mafrost

Don't ask me why, but if it's not interfering with your slider in other ways, consider setting slidesToShow to at least half of your number of slides, which would be 6 for your fiddle. It's a hack, but it solved my problem for now.

http://jsfiddle.net/memvovkz/1/

evalunamain avatar May 26 '15 20:05 evalunamain

@evalunamain Interesting. Will have to try and see if this will work with dynamic content as well, where the number of objects is unknown.

picard102 avatar May 27 '15 06:05 picard102

@picard102 it appears if you use @evalunamain 's method and just use jQuery to get the number of slides before the slider initializes, you should be able to pass in that number divided by 2. Haven't fully tested by it worked when I changed the JS in the fiddle you shared in the initial post.

jcitysinner avatar May 27 '15 18:05 jcitysinner

Maybe someone can help? What if I need to style an active slide? And if slider has more than 1 in slidesToShow, for example, 6 slides. All of them have an slick-active class, and I am using a centerMode: true, so only one slider in the middle has to be active.

makseo avatar Jul 03 '15 12:07 makseo

I think I've dealt with that before @makseo , if you use the beforeChange event, you can figure out which slide is the next slide and then apply a style directly to it.

jcitysinner avatar Jul 03 '15 12:07 jcitysinner

+1

PixelZombie avatar Sep 30 '15 12:09 PixelZombie

+1

albertopriore avatar Oct 08 '15 08:10 albertopriore

+1

gambala avatar Oct 09 '15 13:10 gambala

Hey guys.... had the same problem with a carousel of variable width of items....got a solution for this....

Have tried the solution of evalunamain, and set the slidesToShow option to half of my items, but this way slide controls (arrows) didn't work as expected...

So I go to the code of slick core....and found the lines where infinite is being initialized...here is the code down here:

Slick.prototype.setupInfinite = function() {

    var _ = this,
        i, slideIndex, infiniteCount;

    if (_.options.fade === true) {
        _.options.centerMode = false;
    }

    if (_.options.infinite === true && _.options.fade === false) {

        slideIndex = null;

        if (_.slideCount > _.options.slidesToShow) {

            if (_.options.centerMode === true) {
                infiniteCount = _.options.slidesToShow + 1;
            } else {
                infiniteCount = _.options.slidesToShow;
            }

            for (i = _.slideCount; i > (_.slideCount -
                    infiniteCount); i -= 1) {
                slideIndex = i - 1;
                $(_.$slides[slideIndex]).clone(true).attr('id', '')
                    .attr('data-slick-index', slideIndex - _.slideCount)
                    .prependTo(_.$slideTrack).addClass('slick-cloned');

// added this code here $(.$slides[slideIndex + 1]).clone(true).attr('id', '') .attr('data-slick-index', slideIndex - .slideCount) .prependTo(.$slideTrack).addClass('slick-cloned'); $(.$slides[slideIndex + 2]).clone(true).attr('id', '') .attr('data-slick-index', slideIndex - .slideCount) .prependTo(.$slideTrack).addClass('slick-cloned'); // } for (i = 0; i < infiniteCount; i += 1) { slideIndex = i; $(.$slides[slideIndex]).clone(true).attr('id', '') .attr('data-slick-index', slideIndex + .slideCount) .appendTo(.$slideTrack).addClass('slick-cloned'); // and this code here $(.$slides[slideIndex + 1]).clone(true).attr('id', '') .attr('data-slick-index', slideIndex + .slideCount) .appendTo(.$slideTrack).addClass('slick-cloned'); $(_.$slides[slideIndex + 2]).clone(true).attr('id', '') .attr('data-slick-index', slideIndex + .slideCount) .appendTo(.$slideTrack).addClass('slick-cloned'); // } _.$slideTrack.find('.slick-cloned').find('[id]').each(function() { $(this).attr('id', ''); });

        }

    }

};

so it creates some more clones...... and I suggest to make an option, which can manipulate the number of clones on this position....

Hope this helps....thanks guys.

prod1992 avatar Nov 02 '15 12:11 prod1992

+1

gius80 avatar Dec 15 '15 14:12 gius80

+1

rafa-suagu avatar Dec 16 '15 15:12 rafa-suagu

Hi @prod1992 , I tested your solution and didn't work for my case.

Finding the solution I found one trick: use unFilter function when the init event is fired.

Edit: In my case didn't use variableWidth and also fails

rafa-suagu avatar Dec 21 '15 11:12 rafa-suagu

Thanks, can you provide a snippet for better understanding?

On Monday, 21 December 2015, Rafa Aguilar [email protected] wrote:

Hi prod1992, I tested your solution and didn't work for me case.

Finding the solution I found one trick: use unFilter function when the init event is fired.

— Reply to this email directly or view it on GitHub https://github.com/kenwheeler/slick/issues/1207#issuecomment-166279797.

*Best wishes and have a nice day! *

Levon Grigoryan.

prod1992 avatar Dec 21 '15 13:12 prod1992

I use with angular directive https://github.com/devmark/angular-slick-carousel, if you want to check my issue test the demo of this repo.

For solve, only have to click unFilter button.

rafa-suagu avatar Dec 21 '15 14:12 rafa-suagu

+1

chemoish avatar Dec 22 '15 03:12 chemoish

You can see the error in the next screencast: https://www.dropbox.com/s/rte1569yb7z167t/angular-slick.mov?dl=0

rafa-suagu avatar Dec 22 '15 09:12 rafa-suagu

+1

danielfriis avatar Dec 23 '15 11:12 danielfriis

+1

HonzaMikula avatar Dec 24 '15 17:12 HonzaMikula

I'm off next week so I'll try to get this sorted out folks

kenwheeler avatar Dec 25 '15 04:12 kenwheeler

that would be great 👌

On Fri, Dec 25, 2015 at 8:26 AM, Ken Wheeler [email protected] wrote:

I'm off next week so I'll try to get this sorted out folks

— Reply to this email directly or view it on GitHub https://github.com/kenwheeler/slick/issues/1207#issuecomment-167191108.

*Best wishes and have a nice day! *

Levon Grigoryan.

prod1992 avatar Dec 26 '15 00:12 prod1992

+1, same problem here.

danielmuehlbacher avatar Jan 09 '16 13:01 danielmuehlbacher

Are we all in agreement that the last slide should stick to the right edge?

kenwheeler avatar Jan 09 '16 14:01 kenwheeler

Yes, I agree with that.

On Saturday, 9 January 2016, Ken Wheeler [email protected] wrote:

Are we all in agreement that the last slide should stick to the right edge?

— Reply to this email directly or view it on GitHub https://github.com/kenwheeler/slick/issues/1207#issuecomment-170242120.

*Best wishes and have a nice day! *

Levon Grigoryan.

prod1992 avatar Jan 09 '16 15:01 prod1992

@prod1992 so if its variable width, the last navigable/selectable index should be the one that sticks the last one to the right edge?

kenwheeler avatar Jan 09 '16 15:01 kenwheeler