Sticky (吸顶)
建一个在滚动时可以固定在顶部的内容块,支持配置吸顶元素的ID、层叠顺序、吸顶位置等
支持平台
安卓 | ios | 鸿蒙 | web | 微信小程序 |
---|---|---|---|---|
√ | √ | √ | √ | √ |
示例代码
html
<template>
<t-page>
<t-col main-class="p-30">
<t-card main-class="mb-30" title='Sticky粘性布局'
sub-title="Sticky粘性布局,用于实现元素在页面滚动时固定在指定位置,支持自定义z-index和top值,简单易用。"></t-card>
<t-sticky main-class="w-690" :scrollTop="scrollTop" :stickyTop="0">
<t-view>
<t-button type="p" main-class="w-100%">欢迎使用Tui</t-button>
</t-view>
</t-sticky>
<t-col v-for="i in 3" :key="i" main-class="h-500 tdr tdb mb-30"></t-col>
<t-sticky sticky-top="100rpx" main-class="mb-30" :stickyTop="50" :scrollTop="scrollTop">
<t-button type="p" text-class="f" main-class="w-690">Tui是一个强大的UI库,提供了丰富的组件和灵活的配置。</t-button>
</t-sticky>
<t-col v-for="i in 5" :key="i" main-class="h-500 tdr tdb mb-30"></t-col>
<t-sticky sticky-top="200rpx" main-class="mb-30" :stickyTop="120" :scrollTop="scrollTop">
<t-button type="p">快速导航:首页 | 优惠券 | 会员中心 | 客服支持</t-button>
</t-sticky>
<t-col v-for="i in 5" :key="i" main-class="h-800 tdr tdb mb-30"></t-col>
</t-col>
</t-page>
</template>
<script setup>
const scrollTop = ref<number>(0)
onPageScroll((e : OnPageScrollOptions) => {
scrollTop.value = e.scrollTop
})
import { TuiGuid } from '@/uni_modules/tui-plugins';
const guid = ref(TuiGuid(20))
</script>
属性
名称 | 类型 | 默认值 | 说明 | 可选值 |
---|---|---|---|---|
size | String | mini | 组件尺寸 | large(大尺寸), medium(中尺寸), small(小尺寸), mini(迷你) |
type | String | "" | 组件类型 | info(信息), primary(正常), error(错误), warning(警告), success(成功) |
disabled | Boolean | false | 组件是否禁用 | false, true |
stop | Boolean | false | 是否阻止事件冒泡(Tui统一写法处理事件冒泡) | false, true |
hover | Boolean | true | 是否有点击效果 | false, true |
path | String | "" | 点击组件后跳转的页面路径,如果为空则响应点击事件,如果不为空则跳转页面不会响应单击事件。 | - |
mainClass | String | "" | 组件根节点的样式 | - |
nativeClass | String | "" | 组件根节点原生样式 | - |
effect | String | "normal" | 组件显示主题 | normal(正常), dark(深色), light(浅色), plain(镂空) |
stickyTop | Number | 1 | 吸顶位置,默认为0 | |
scrollTop | Number | 1 | 滚动组件的top值 | |
insId | String | `` | 吸顶元素的ID | |
zIndex | Number | 88 | 层叠顺序 |
事件
名称 | 返回参数 | 说明 |
---|---|---|
click | (e : UniPointerEvent) | - |
插槽
名称 | 返回值 | 说明 |
---|---|---|
default | - |