-1

我正在使用react-responsive-carousel库。在这里,我想将默认指标CSS,点形状更改为线条形状。我的代码是,

 <CarouselWrapper
      sx={{ marginTop: "124px", maxHeight: "486px", minHeight: "150px" }}
    >
      <Carousel autoPlay infiniteLoop showArrows={false}>
        <div>
          <Image src={image1} />
        </div>
        <div>
          <Image src={image1} />
        </div>
        <div>
          <Image src={image1} />
        </div>
      </Carousel>
    </CarouselWrapper>

这些指标的当前形态,

在此处输入图像描述

是否可以自定义点形状指示器?

4

2 回答 2

2

如果使用 SCSS 并且需要较少的定制,这是一个解决方案。使用包装选择器,您可以使用:

  .yourSelector {
    :global(.carousel .control-dots .dot) {
            background-color: blue;
          }
        }
于 2022-02-24T08:44:57.750 回答
0

是的,您可以使用 JSX 将renderIndicator属性作为函数传递给Carousel组件来自定义点。您可以查看此沙箱,了解此用法的实时工作示例。

<Carousel
      autoPlay
      infiniteLoop
      showArrows={false}
      renderIndicator={(onClickHandler, isSelected, index, label) => {
        const defStyle = { marginLeft: 20, color: "white", cursor: "pointer" };
        const style = isSelected
          ? { ...defStyle, color: "red" }
          : { ...defStyle };
        return (
          <span
            style={style}
            onClick={onClickHandler}
            onKeyDown={onClickHandler}
            value={index}
            key={index}
            role="button"
            tabIndex={0}
            aria-label={`${label} ${index + 1}`}
          >
            {"cust " + index}
          </span>
        );
      }}
    >
      <div>
        <img src={"1.jpeg"} />
      </div>
      <div>
        <img src={"2.jpeg"} />
      </div>
      <div>
        <img src={"3.jpeg"} />
      </div>
    </Carousel>
);
于 2021-10-31T07:56:57.243 回答