Skip to content
API 风格:

Affix 固钉 ​

滚动吸顶 / 吸底。用 IntersectionObserver 检测占位越界(无 scroll 节流开销,无 IO 环境自动回退 scroll 监听)。

基础用法 ​

吸顶
吸顶工具条

offset-bottom 触发吸底(优先于 offset-top);target 指定滚动监听容器(默认视口)。

吸底
吸底工具条(offset-bottom)
vue
<script setup lang="ts">
</script>

<template>
  <!-- 吸底 -->
  <LhAffix :offset-bottom="8">
    <div class="demo-affix-bar">吸底工具条</div>
  </LhAffix>
</template>
vue
<script>
export default {}
</script>

<template>
  <!-- 吸底 -->
  <LhAffix :offset-bottom="8">
    <div class="demo-affix-bar">吸底工具条</div>
  </LhAffix>
</template>
vue
<script setup lang="ts">
</script>

<template>
  <!-- 吸顶 -->
  <LhAffix :offset-top="8">
    <div class="demo-affix-bar">吸顶工具条</div>
  </LhAffix>
</template>
vue
<script>
export default {}
</script>

<template>
  <!-- 吸顶 -->
  <LhAffix :offset-top="8">
    <div class="demo-affix-bar">吸顶工具条</div>
  </LhAffix>
</template>

API ​

LhAffix Props ​

属性名说明类型默认值
offsetTop距视口顶部多少像素触发吸顶number0
offsetBottom距视口底部多少像素触发吸底(优先于 offsetTop)number0
target滚动监听容器(选择器或元素,默认视口)string | HTMLElement—
sxsx 快速布局属性LhSxProps—

Events ​

事件名说明回调参数
change固定态切换时触发(进入或离开吸顶 / 吸底)(fixed: boolean)

无障碍 ​

  • 无特殊 role;固定态不影响文档流焦点顺序
  • 固定态以占位元素撑高,避免布局跳动

类型定义 ​

本组件对外导出的 TypeScript 类型结构如下(自动提取自 packages/components/affix/src/types.ts 与 @lh-ui/share/core/* 源码,点击各条目展开查看完整定义;属性说明见上方 Props 表):

LhAffixProps
ts
export interface LhAffixProps {
  /** 距视口顶部多少像素触发吸顶 */
  offsetTop?: number
  /** 距视口底部多少像素触发吸底(优先于 offsetTop) */
  offsetBottom?: number
  /** 滚动监听容器(选择器或元素,默认视口) */
  target?: string | HTMLElement
  /** sx 快速布局属性 */
  sx?: LhSxProps
}