提交 04977efd 编写于 作者: H hdx

feat: add api pageScrollTo

上级 f46c2375
......@@ -563,6 +563,13 @@
}
}
,{
"path" : "pages/API/page-scrollTo/page-scrollTo",
"style" : {
"navigationBarTitleText": "pageScrollTo",
"enablePullDownRefresh": false
}
}
],
"globalStyle": {
"pageOrientation": "portrait",
......
const PAGE_PATH = '/pages/API/page-scrollTo/page-scrollTo'
describe('page-scrollTo', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
})
// TODO
// it('scrollTo', async () => {
// const btnScrollTo = await page.$('.btn-scrollTo')
// await toggle.tap()
// await page.waitFor(50)
// expect(await page.scrollTop).toBe(100)
// })
// it('scrollToElement', async () => {
// const btnScrollTo = await page.$('.btn-scrollToElement')
// const scrollToElement = await page.$('.custom-element')
// await btnScrollTo.tap()
// await page.waitFor(50)
// const offset = await scrollToElement.offset()
// expect(offset.top).toBe(0)
// })
})
\ No newline at end of file
<template>
<view class="uni-padding-wrap">
<page-head :title="title"></page-head>
<button type="default" class="btn-scrollTo" @click="scrollTo">scrollTo</button>
<button type="default" class="btn-scrollToElement" @click="scrollToElement">scrollToElement</button>
<view class="uni-list" v-for="(_, index) in 10" :key="index">
<view class="uni-list-cell list-item">{{ index }}</view>
</view>
<view class="custom-element">scrollTo-custom-element</view>
<view class="uni-list" v-for="(_, index2) in 10" :key="index2">
<view class="uni-list-cell list-item">{{ index2 }}</view>
</view>
</view>
</template>
<script lang="ts">
export default {
data() {
return {
title: 'pageScrollTo'
}
},
methods: {
scrollTo() {
uni.pageScrollTo({
scrollTop: 100,
duration: 300,
success: () => {
console.log('success')
}
})
},
scrollToElement() {
uni.pageScrollTo({
selector: '.custom-element',
duration: 300,
success: () => {
console.log('success')
}
})
}
}
}
</script>
<style>
.list-item {
height: 100px;
padding-left: 30px;
}
</style>
\ No newline at end of file
......@@ -112,6 +112,11 @@
url: "toast",
enable: true
},
{
name: "将页面滚动到目标位置",
url: "page-scrollTo",
enable: true
},
] as Page[],
},
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册