后浪云百度小程序教程:swan.pageScrollTo
- swan.pageScrollTo
- 方法参数
- object 参数说明
- 示例
- 代码示例 1:页面滚动到顶部 / 底部
- 代码示例 2:页面滚动到底部
- 错误码
- Android
- iOS
- 方法参数
swan.pageScrollTo
解释:将页面滚动到目标位置(可以设置滚动动画时长)。
方法参数
Object object
object 参数说明
属性名 | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
scrollTop |
Number |
是 |
滚动到页面的目标位置(单位:px) |
|
duration |
Number |
否 |
300 |
滚动动画的时长(单位:ms) |
success |
Function |
否 |
接口调用成功的回调函数 |
|
fail |
Function |
否 |
接口调用失败的回调函数 |
|
complete |
Function |
否 |
接口调用结束的回调函数(调用成功、失败都会执行) |
示例
跳转编辑工具
在开发者工具中打开
在 WEB IDE 中打开
扫码体验
代码示例
请使用百度APP扫码
代码示例 1:页面滚动到顶部 / 底部
- SWAN
- JS
<view class="wrap">
<image mode="aspectFit" class="image" src="https://b.bdstatic.com/miniapp/images/longImage.png"></image>
<view class="swan-security-padding-bottom flex-button">
<button type="primary" disabled="{{disabled}}" bindtap="scrollToBottom">滚动到页面底部</button>
<button type="primary" disabled="{{!disabled}}" bindtap="scrollToTop">返回顶部</button>
</view>
</view>
代码示例 2:页面滚动到底部
在开发者工具中打开
在开发者工具中打开
在 WEB IDE 中打开
- SWAN
- JS
<view class="wrap">
<image class="image" src="https://b.bdstatic.com/miniapp/images/longImage.png"></image>
<view class="swan-security-padding-bottom flex-button">
<button type="primary" bindtap="scrollToBottom">滚动到页面底部</button>
</view>
</view>
错误码
Android
错误码 | 说明 |
---|---|
202 |
解析失败,请检查参数是否正确 |
1001 |
执行失败 |
iOS
错误码 | 说明 |
---|---|
202 |
解析失败,请检查参数是否正确 |
版权声明:
作者:后浪云
链接:https://www.idc.net/help/186691/
文章版权归作者所有,未经允许请勿转载。
THE END