我正在使用alice-carousel(https://github.com/maxmarinich/react-alice-carousel/blob/master/README.md)制作走马灯组件,但是在自定义箭头时遇到了问题。代码如下:
上述代码更改了
export const Carousel: React.FC<CarouselProps> = ({text }) => {
const [activeIndex, setActiveIndex] = useState(0);
const items = ["item1","item2","item3"]
const slidePrev = () => {
activeIndex==0?(
setActiveIndex(items.length-1)):
setActiveIndex(activeIndex - 2);
};
const slideNext = () => {
activeIndex==items.length-1?(
setActiveIndex(0))
: setActiveIndex(activeIndex + 2)
};
return(
<div className="grid grid-cols-3">
<div className="col-span-2>
{text}
</div>
<div className="flex justify-end">
<button className="px-8" onClick={slidePrev}><ArrowL/></button>
<button className="px-8" onClick={slideNext}><ArrowR/></button>
</div>
<div className="col-span-3 px-10">
<AliceCarousel
mouseTracking
disableDotsControls
disableButtonsControls
activeIndex={activeIndex}
items={items}
responsive={responsive}
controlsStrategy="responsive"
autoPlay={true}
autoPlayInterval={5000}
infinite={true}
keyboardNavigation={true}
/>
</div>
</div>
)}
上述代码更改了
activeIndex
,从而改变了项目的显示顺序,但它没有使用“slide”动画。我已经查看了库中提供的示例,但似乎无法使其平滑地滑动。我做错了什么?
renderPrevButton={() => { <div><ArrowL/></div>}}
。我还想自定义这些控件的位置(在滑块上方的右上角)。 - DworoAliceCarousel
中移除了 "disableButtonsControls" 和 "activeIndex" 属性了吗,@Dworo? - nimarenderPrevButton={( )=>{return <ArrowL />}}
最终起作用了。 - Dworo