metafizzy / flickity

:leaves: Touch, responsive, flickable carousels
https://flickity.metafizzy.co
7.52k stars 605 forks source link

Center slide on select ( active ), exactly that asNavFor does but in a normal slider. #1024

Closed zzseba78 closed 4 years ago

zzseba78 commented 4 years ago

Is there a way to center selected slide, just like asNavFor does, but in a single slider? Because the slider act as navigation that loads with ajax some content. Thanks!

clarknelson commented 4 years ago

Have you tried this option: https://flickity.metafizzy.co/options.html#cellalign

zzseba78 commented 4 years ago

Thanks for your response! yes, but this is for center the slider items, i need to center the item when clicked ( active ), just like asNavFor navigation does.

clarknelson commented 4 years ago

It should center as you desire, make sure the slides are not 100% width, but a natural width based on their content

zzseba78 commented 4 years ago

Center the slider is not what i need, i need to center the active item when is selected. You click on any slider item, it highlight ( i do it with css ) and the item moves to center.

https://flickity.metafizzy.co/options.html#asnavfor Just like this one: Captura de Pantalla 2020-02-13 a la(s) 17 08 25

clarknelson commented 4 years ago

Do you have a live example? I believe "cellAlign" will add this functionality. The active slide should be centered in the gallery.

zzseba78 commented 4 years ago

@clarknelson Hi! No it doesn´t, it just center items. https://flickity.metafizzy.co/options.html#cellalign

clarknelson commented 4 years ago

Isn't this what you are looking for?

image

zzseba78 commented 4 years ago

@clarknelson No, i need to center the clicked slider item, just like asnav does.

clarknelson commented 4 years ago

Are you using isNavFor? Did you see that it requires an extra package if you are not using the bundled version. Can see more configuration options in this repo: https://github.com/metafizzy/flickity-as-nav-for

zzseba78 commented 4 years ago

Hi @clarknelson ! I want the same behavior as isNavFor ( i mean, each time you click the item, item is centered in slider ), but is not a sub nav, is just one slider that loads ajax content. Is this possible?

nickersonm commented 4 years ago

@zzseba78 Do you mean centering an item that is to the side when it is clicked? This should do it:

flkty.on( 'staticClick', function( event, pointer, cellElement, cellIndex ) {
    if ( !cellElement ) {
        return;
    }
    flkty.selectCell(cellElement, false, false);
});