Appearance
mp-scroll-to 滚动到指定位置
指定何时出现(滚动到某个阈值,某个元素出现或消失)、点击滚动到指定位置(某个距离、某个元素)
TIP
若该组件不满足使用,可使用 useScrollTo 自行实现
代码演示
滚动到达某个阈值时显示
当页面滚动到距离顶部 200px 时显示,点击滚动回顶部(0px)
html
<mp-scroll-to :scroll-top="0" :visible-threshold="200" />
自定义位置和样式
按钮图标为向下(bottom),按钮悬浮在左边 30rpx 的位置,当页面滚动到距离顶部 200px 时显示,点击滚动到 250px 的位置
html
<mp-scroll-to
icon="bottom"
:scroll-top="250"
:styles="{right: 'unset', left: '30rpx'}"
:visible-threshold="-200"
/>
监听指定元素触达某个距离时显示(自定义 slot)
当 .card-5
滚动到触达 getNavbarHeight
的时候,悬浮按钮显示,滚动回顶部(0px)
html
<mp-scroll-to
observe=".card-5"
:observe-offset="{top: -device.getNavbarHeight()}"
:scroll-top="0"
:styles="{width: '100rpx', height: '100rpx'}"
>
<image
class="scroll-to-top-image"
src="https://cloud-minapp-41176.cloud.ifanrusercontent.com/1qul9sK9mqJKqZr6.png"
/>
</mp-scroll-to>
滚动到指定元素
始终显示,当点击到时候滚动到 .card-12
距离顶部 getNavbarHeight
的位置。
html
<mp-scroll-to
icon="bottom"
:offset-top="-device.getNavbarHeight()"
selector=".card-12"
:styles="{right: 'unset', left: '30rpx'}"
:visible-threshold="0"
>
</mp-scroll-to>
API
Props
Slots
Name | Description | Bindings |
---|---|---|
default | 自定义内容 |