react-multi-carousel icon indicating copy to clipboard operation
react-multi-carousel copied to clipboard

Center mode broken when setting the item width

Open plumest opened this issue 4 years ago • 4 comments

Describe the bug The current picture does not place at the center of the screen when I add my width to react-multi-carousel-item by setting itemClass. I also set the centerMode and infinite to be true

To Reproduce Steps to reproduce the behavior:

  1. Set the Carousel centerMode and infinite to true
  2. Adding itemClass and set some static width with !important like this
.image-item {
    padding: 0 10px;
    width: 400px !important;
}

Expected behavior I want the current image to always place at the center of the screen. and need to set some constants width to those images.

Screenshots Screen Shot 2564-07-16 at 12 48 43

Desktop (please complete the following information):

  • OS: MacOS
  • Browser chrome
  • Version 91.0.4472.114

Additional context I try to add additionalTransfrom to fix it but it is still broken if I resize or change the current focus.

Reproduction Link to https://codesandbox.io/s/react-multi-carousel-playground-forked-hrs0l?file=/components/Simple.js

plumest avatar Jul 12 '21 11:07 plumest

I try to set the Carousel state using React-dev-tools and its work by this equation

CarouselRef.current.state.transform = ( currentSlide * -myWidth ) - ( ( ( myWidth * 2 ) - containerWidth ) / 4 );

But I can't update its state. Is there any way to update the Carousel state?

plumest avatar Jul 16 '21 06:07 plumest

any solution to this?

lim1017 avatar May 05 '22 17:05 lim1017

I'm using tailwind and was able to achive this by adding itemClass to the carrousel

itemClass="px-1 flex justify-center"

you can create your own class and added there

itemClass={myCustomCSSClass}

import css

.image-item {
  display: "flex";
  justify-content: "center";
  margin: 0 1px;
}

I haven't try it but I think this should work just fine.

da8ah avatar Sep 27 '23 22:09 da8ah

any solution to this?

XuanDuLe avatar Apr 11 '24 17:04 XuanDuLe