JGuang

Swiper

Swiper · Ant Design Mobile

Preview
npm install antd-mobile@5.43.0

Swiper

A set of rotating areas.

Install

npm install antd-mobile@5.43.0

antd-mobile is for mobile web, not React Native or Mini Programs. React 19 projects must register createRoot with unstableSetRender at the entry, or imperative APIs such as Toast and Dialog cannot render. Switch dark mode with <html data-prefers-color-scheme="dark">.

Examples come from the official Ant Design Mobile repository (MIT) at the commit published as npm 5.43.0. Presentation helpers such as DemoBlock are JGuang rewrites, not antd-mobile APIs.

A set of rotating areas.

When to Use

  • When there is a set of flat content.
  • When the content space is insufficient, it can be stored in the form of a revolving lantern for carousel display.
  • Often used for a set of images or card carousels.

Demos

Basic Usage

Slides which are not full-width

Indicators

Full Page Guide

Vertical

When you use a vertical Swiper, be sure to set its height through the --height CSS variable, otherwise the Swiper will display abnormally.

Virtual Scroll

Use total with renderProps for render. Not support loop

Swiper

Props

NameDescriptionTypeDefaultVersion
allowTouchMoveWhether to allow gesture slidingbooleantrue
autoplayWhether to switch automaticallybooleanfalse
autoplayIntervalAutomatic switching interval, the unit is msnumber3000
defaultIndexThe initial positionnumber0
directionLayout direction'horizontal' | 'vertical''horizontal'
indicatorRender a customized indicator(total: number, current: number) => ReactNode-
indicatorPropsRelated attributes of the indicatorsupport PageIndicator color style className prop-
loopWhether to loopbooleanfalse
onIndexChangeTriggered on index is changed(index: number, info: { source: SwiperIndexChangeSource }) => void-
rubberbandWhether to enable the rubberband effect.booleantrue
slideSizeThe slide width in percentagenumber100
stuckAtBoundaryWhether to stuck at boundary in order to prevent white spaces. Only available when loop is false and slideWidth < 100.booleantrue
trackOffsetThe track offset in percentagenumber0
totalVirtual scroll config total size which should work with renderProps. (Not support loop)number5.34.0
stopPropagationStop the propagation of some events.PropagationEvent[][]5.28.0
type PropagationEvent = 'mouseup' | 'mousemove' | 'mousedown'
type SwiperIndexChangeSource = 'auto' | 'swipe' | 'resize'

CSS Variables

NameDescriptionDefault
--border-radiusrounded corners of the overall component0
--heightheightauto
--track-paddingpadding in the track area0
--widthwidth100%

Ref

NameDescriptionType
swipeNextSwitch to the next one() => void
swipePrevSwitch to the previous one() => void
swipeToSwitch to the specified index(index: number) => void

Swiper.Item

Props

NameDescriptionTypeDefault
onClickTriggered when the slider is clicked(e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void-