Skip to main content

Bear Carousel

If you want to do some customization

import BearCarousel from 'bear-react-carousel';

<BearCarousel
// ...ignore some
height="250px"
/>

Props

Props NameTypeRequiredDefaultDescription
styleCSS.Properties
classNamestring
setController(controller: Controller) => voidManual control carousel
syncCarouselRefRefObject<BearCarousel>Auto sync control bear-react-carousel
dataBearSlideCard | BearSlideImage []Slide item data
slidesPerViewnumber | auto1The number of items displayed in the container
slidesPerGroupnumber1Show several items on one page
heightstring | IAspectRatioCarouse height
spaceBetweennumberdistance between items
moveTimenumber500(ms)Slide moving time
isCenteredSlidesbooleanfalseCenter display mode
isEnableLoopbooleanfalseRepeat display loop mode
isEnablePaginationbooleanfalseShow pagination
isEnableNavButtonbooleanfalseShow nav button
isEnableMouseMovebooleantrueMouse drag switch
isEnableAutoPlaybooleanfalseAuto slide item
isEnableGPURenderbooleanfalseWhether to use GPURender, if the card hierarchy is more complex, you can turn it on to make the sliding smoother, but it will take up more memory.
isLazybooleanbg Lazy loading
renderPreloader() => JSX.Elementbg Lazy mode preloader content
autoPlayTimenumber5000(ms)Auto slide item time
initStartPlayTimenumber5000(ms)Init start auto slide item time
renderNavButtonTRenderNavButtonCustom render nav button
renderPaginationTRenderPaginationCustom render pagination
breakpointsIPropsBreakpointsRWD breakpoints
onSlideChangeTOnSlideChangeCarousel state change event
onAnimationEndTOnAnimationEndslider onAnimationEnd event
moveEffectIMoveEffectCarousel card move effect
movePercentagenumber0.1Movement distance ratio (judgment for switching between previous and next pages)
onMount() => voidCarousel componentDidMount event
isDebugbooleanVisible debug info

Controller

Controller

Method NameTypeDefaultDescription
slideToPrevPage() => voidSlide to prev page
slideToNextPage() => voidSlide to next page
slideToPage(page: number, isUseAnimation = true) => voidSlide target page
slideToSourceIndex(slideIndex: number, options?: {isUseAnimation?: boolean, isEmitEvent?: boolean}) => voidSlide target item

IAspectRatio

Here we use the proportional property of CSS aspect-ratio (not the padding-bottom % method)

Props NameTypeRequiredDefaultDescription
widthRationumberproportionately width
heightRationumberproportionately high

TRenderNavButton

type TRenderNavButton = (toPrev: () => void, toNext: () => void) => void

TRenderPagination

type TRenderPagination = (pageTotal: number) => JSX.Element[]

IPropsBreakpoints

interface IPropsBreakpoints {
[key: number]: Partial<IBreakpointSetting>
}

interface IBreakpointSetting {
slidesPerView: TSlidesPerView
slidesPerGroup: number
height?: string|IAspectRatio
spaceBetween: number
isCenteredSlides: boolean
isEnableLoop: boolean
isEnablePageContent: boolean
isEnablePagination: boolean
isEnableNavButton: boolean
isEnableMouseMove: boolean
isEnableAutoPlay: boolean
}

TOnSlideChange

type TOnSlideChange = (carouselState: ICarouselState) => void

interface ICarouselState {
source: {
activeIndex: number
lastIndex: number
total: number
}
virtual: {
activeIndex: number
lastIndex: number
total: number
}
page: {
activePage: number
total: number
}
}

TOnAnimationEnd

當項目移動時動畫結束事件回傳資訊

type TOnAnimationEnd = (carouselState: ICarouselState, elementor: Elementor) => void

class Elementor {
_rootRef: RefObject<HTMLDivElement> = createRef();
_containerRef: RefObject<HTMLDivElement> = createRef();
_pageGroupRef: RefObject<HTMLDivElement> = createRef();
_navGroupRef: RefObject<HTMLDivElement> = createRef();
_slideItemRefs: IMultiRefObject<Array<HTMLDivElement>> = createRef();
_pageRefs: IMultiRefObject<Array<HTMLDivElement>> = createRef();

// ...ignore
}

IMoveEffect

Apply different dynamic effects on the move, Currently only transformY is supported, please issue if you have other needs

MoveEffect Example

Props NameTypeRequiredDefaultDescription
transformYstringtransformY px
moveTimenumber.5stransform time