2 回答

TA貢獻1874條經驗 獲得超12個贊
您可以使用每次滑動之前和之后調用的beforeChange
和回調。afterChange
如果您只想檢測按鈕單擊(而不是鍵盤滑動或拖動),則可以創建新的按鈕組件并將它們作為自定義箭頭傳遞。您的自定義按鈕將收到道具/狀態列表;其中之一是 的處理react-multi-carousel
程序onClick
。
您可以將自定義按鈕作為道具 (customLeftArrow
和customRightArrow
) 傳遞到輪播。
function CustomRightArrow({ onClick }) {
? function handleClick() {
? ? // do whatever you want on the right button click
? ? console.log('Right button clicked, go to next slide');
? ? // ... and don't forget to call onClick to slide
? ? onClick();
? }
? return (
? ? <button
? ? ? onClick={handleClick}
? ? ? aria-label="Go to next slide"
? ? ? className="react-multiple-carousel__arrow react-multiple-carousel__arrow--right"
? ? />
? );
}
function App() {
? return (
? ? <Carousel
? ? ? customLeftArrow={<CustomLeftArrow />}
? ? ? customRightArrow={<CustomRightArrow />}
? ? ? infinite
? ? ? keyBoardControl
? ? >
? ? ? {images.map((image, i) => {
? ? ? ? return (
? ? ? ? ? <img
? ? ? ? ? ? key={i}
? ? ? ? ? ? style={{ width: '100%', height: '100%' }}
? ? ? ? ? ? src={image}
? ? ? ? ? ? alt=""
? ? ? ? ? />
? ? ? ? );
? ? ? })}
? ? </Carousel>
? );
}
添加回答
舉報