getSwiperIndex
Start from API_LEVEL
2.0. Please refer to API_LEVEL.
Get the scroll position of the current page, only if the page scroll mode is SCROLL_MODE_SWIPER or SCROLL_MODE_SWIPER_HORIZONTAL return the index of the current item (starting from 1), otherwise return undefined.
Type
function getSwiperIndex(): Result
Parameters
Result
| Type | Description |
|---|---|
number|undefined | If the page scroll mode is SCROLL_MODE_SWIPER or SCROLL_MODE_SWIPER_HORIZONTAL, the value is the index of the current item (starting from 1). Otherwise, it is undefined. |
Example
import { setScrollMode, swipeToIndex, getSwiperIndex, SCROLL_MODE_SWIPER } from '@zos/page'
setScrollMode({
mode: SCROLL_MODE_SWIPER,
options: {
height: 480,
count: 10,
},
})
swipeToIndex({
index: 5,
})
const currentIndex = getSwiperIndex()
console.log(currentIndex)