akiran / akiran/react-slick

CenterMode with Infinite and Variable Width not centering properly

Aperta
#2,347 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
11.9k
Fork
2.1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

The slider is sitting in a container that is 100% the width of the viewport and width is determined by each image element child which is ultimately governed by the height of the parent container. These are native images in an img tag so they proportionally scale their aspect ratio according to the height.

The centering is off from the center by a small amount that is variable on each item. I'm not sure what is wrong with the centering calculation, but it is wrong and producing off-center results. See several screenshots below.

Screenshot 2024-02-16 at 3 47 27 PM

Screenshot 2024-03-06 at 8 47 55 PM

Screenshot 2024-03-06 at 8 48 29 PM

![PixelSnap 2024-03-06 at 20 55 58@2x](https://github.com/akiran/react-slick/assets/202188/96f2e9b8-93d8-42bb-b6a8-c898c8299c00)

``

```javascript
const slide_settings = {
infinite: true,
slidesToScroll: 1,
slidesToShow: 1,
arrows: false,
dots: false,
speed: 400,
swipe: true,
swipeToSlide: true,
easing: "ease-out",
className: "projectslider",
variableWidth: true,
centerMode: true,
centerPadding: "0px",
afterChange: (index) => {
setCurrentMedia(index);
},
};
```

```css
.projectslider {
height: 100%;
padding: 0;

.slick-list {
height: 100%;

.slick-track {
height: 100%;

.slick-slide {
height: 100%;

> div {
height: 100%;
width: auto;

figure {
outline: none;
height: 100%;
width: auto !important;
margin: 0;
padding: 0 25px;
position: relative;
z-index: 1;

img,
video {
cursor: pointer;
height: 100%;
outline: none;
width: auto;
}
}
}
}
}
}
}
```

```javascript



{mediaData.map((media, index) =>
media.type === "videotype" ? (
goToSlide(index)} key={index}>




) : (
goToSlide(index)}>
{media.caption}

)
)}


```

You can see a live version [here](https://studio-jarvis-git-v2-studio-jarvis.vercel.app/).

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.