Anw*_*ain 5 css responsive-design reactjs next.js react-responsive-carousel
我正在使用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>
Run Code Online (Sandbox Code Playgroud)
这些指标的当前形状,
是否可以自定义点形状指示器?
renderIndicator是的,您可以使用 JSX 将prop 作为函数传递给组件来自定义点Carousel。您可以查看此 stackblitz,了解此用法的实时工作示例。
<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>
);
Run Code Online (Sandbox Code Playgroud)
如果使用 SCSS 并且需要较少的定制,这是一个解决方案。使用包装选择器,您可以使用:
.yourSelector {
:global(.carousel .control-dots .dot) {
background-color: blue;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15337 次 |
| 最近记录: |