Skip to main content
版本:v3

getSwiperIndex

API_LEVEL 2.0 开始支持,API 兼容性请参考 API_LEVEL

获取当前页面的滚动位置,仅当页面滚动模式为 SCROLL_MODE_SWIPERSCROLL_MODE_SWIPER_HORIZONTAL 返回当前项目的索引(从 1 开始),否则返回 undefined

类型

function getSwiperIndex(): Result

参数

Result

类型说明
number|undefined页面滚动模式为 SCROLL_MODE_SWIPERSCROLL_MODE_SWIPER_HORIZONTAL 时,值为当前项目的索引(从 1 开始)。否则为 undefined

代码示例

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)