Skip to content

FloatButton 悬浮按钮

固定在页面边缘的悬浮操作按钮,常用于承载页面级的高频操作(如返回顶部、客服、菜单等)。对标 Element Plus el-float-button 和 Ant Design Vue a-float-button

💡 本页 demo 说明:组件默认 position: fixed,在文档页面中会飞出 demo 区域遮住其他章节。为避免这种情况,所有 demo 都用 :deepposition 在容器内覆盖为 absoluterelative(横排对比时),实际项目使用中按钮会按设计固定在视口。

基础用法

最基本的用法,默认在右下角显示一个圆形图标按钮。

形状与类型

通过 shape 设置形状(circle 圆形 / square 方形),通过 type 设置主题色。

尺寸

通过 size 设置按钮尺寸,支持 default(48px)、small(36px)、large(56px)。

悬停提示

通过 tooltip 属性为按钮添加悬停提示,提示位置默认为左侧。

自定义图标与内容

通过 icon 属性传入图标 class,或使用 icon 插槽插入任意自定义内容。

客服

回到顶部

通过 back-to-top 启用回到顶部模式,组件会监听滚动事件并在滚动距离超过 visibilityHeight 时显示。本 demo 监听下方可滚动容器(通过 target 指定)。

滚动此容器查看右下角返回顶部按钮(第 1 段)

滚动此容器查看右下角返回顶部按钮(第 2 段)

滚动此容器查看右下角返回顶部按钮(第 3 段)

滚动此容器查看右下角返回顶部按钮(第 4 段)

滚动此容器查看右下角返回顶部按钮(第 5 段)

滚动此容器查看右下角返回顶部按钮(第 6 段)

滚动此容器查看右下角返回顶部按钮(第 7 段)

滚动此容器查看右下角返回顶部按钮(第 8 段)

滚动此容器查看右下角返回顶部按钮(第 9 段)

滚动此容器查看右下角返回顶部按钮(第 10 段)

滚动此容器查看右下角返回顶部按钮(第 11 段)

滚动此容器查看右下角返回顶部按钮(第 12 段)

滚动此容器查看右下角返回顶部按钮(第 13 段)

滚动此容器查看右下角返回顶部按钮(第 14 段)

滚动此容器查看右下角返回顶部按钮(第 15 段)

滚动此容器查看右下角返回顶部按钮(第 16 段)

滚动此容器查看右下角返回顶部按钮(第 17 段)

滚动此容器查看右下角返回顶部按钮(第 18 段)

滚动此容器查看右下角返回顶部按钮(第 19 段)

滚动此容器查看右下角返回顶部按钮(第 20 段)

徽标

通过 badge / badge-dot 属性为按钮添加数字徽标或小红点。

12
99
99+

位置

通过 position 属性设置按钮的默认位置,可使用 right / bottom / left / top 调整偏移量。

悬浮按钮组

使用 ZcFloatButtonGroup 将多个悬浮按钮组合在一起,支持可折叠展开。

可折叠按钮组

通过 collapsible 启用折叠模式,配合 trigger="hover"trigger="click" 控制展开方式。

禁用状态

通过 disabled 禁用按钮交互。

自定义容器滚动

通过 target 属性指定滚动容器,配合 back-to-top 使用。

容器内滚动内容(第 1 段)

容器内滚动内容(第 2 段)

容器内滚动内容(第 3 段)

容器内滚动内容(第 4 段)

容器内滚动内容(第 5 段)

容器内滚动内容(第 6 段)

容器内滚动内容(第 7 段)

容器内滚动内容(第 8 段)

容器内滚动内容(第 9 段)

容器内滚动内容(第 10 段)

容器内滚动内容(第 11 段)

容器内滚动内容(第 12 段)

容器内滚动内容(第 13 段)

容器内滚动内容(第 14 段)

容器内滚动内容(第 15 段)

容器内滚动内容(第 16 段)

容器内滚动内容(第 17 段)

容器内滚动内容(第 18 段)

容器内滚动内容(第 19 段)

容器内滚动内容(第 20 段)

容器内滚动内容(第 21 段)

容器内滚动内容(第 22 段)

容器内滚动内容(第 23 段)

容器内滚动内容(第 24 段)

容器内滚动内容(第 25 段)

容器内滚动内容(第 26 段)

容器内滚动内容(第 27 段)

容器内滚动内容(第 28 段)

容器内滚动内容(第 29 段)

容器内滚动内容(第 30 段)

CSS 变量自定义

通过覆盖组件内部的 CSS 变量来定制按钮外观。

FloatButton API

Props

参数说明类型默认值
shape按钮形状'circle' | 'square''circle'
type按钮类型'primary' | 'default' | 'success' | 'warning' | 'danger''default'
size按钮尺寸'default' | 'small' | 'large''default'
icon图标 class(如 iconfont 类名)string''
tooltip悬停提示文本string''
position按钮位置'top-right' | 'top-left' | 'bottom-right' | 'bottom-left''bottom-right'
right距右侧偏移 (px)number40
bottom距底部偏移 (px)number40
left距左侧偏移 (px)number40
top距顶部偏移 (px)number40
badge徽标值(数字或文本)string | number''
badgeMax徽标最大值number99
badgeDot是否显示为红点booleanfalse
disabled是否禁用booleanfalse
backToTop是否为回到顶部按钮(自动监听滚动)booleanfalse
visibilityHeight显示阈值(px,仅在 backToTop 模式下生效)number200
target滚动目标选择器string''(window)
zIndex自定义 z-indexnumber999
ariaLabel无障碍标签string''(自动从 tooltip/backToTop 推断)

Events

事件名说明回调参数
click点击时触发(event: MouseEvent)
showback-to-top 按钮变为可见时触发
hideback-to-top 按钮变为隐藏时触发

Slots

插槽名说明
icon自定义图标内容(当 icon prop 为空时生效)
default自定义按钮内容(替换默认图标)

FloatButtonGroup API

Props

参数说明类型默认值
shape组内按钮形状'circle' | 'square''circle'
type组内按钮类型'primary' | 'default' | 'success' | 'warning' | 'danger''default'
collapsible是否可折叠booleanfalse
trigger折叠触发方式'hover' | 'click''hover'
position组位置'top-right' | 'top-left' | 'bottom-right' | 'bottom-left''bottom-right'
right距右侧偏移 (px)number40
bottom距底部偏移 (px)number40
left距左侧偏移 (px)number40
top距顶部偏移 (px)number40

Slots

插槽名说明
default组内的 ZcFloatButton 按钮

CSS 变量

变量名说明默认值
--zc-float-button-bg-color背景色var(--color-zc-white)
--zc-float-button-text-color文字/图标色var(--color-zc-text-regular)
--zc-float-button-border-color边框色var(--color-zc-border-light)
--zc-float-button-hover-bg-color悬停背景色var(--color-zc-fill-light)
--zc-float-button-hover-text-color悬停文字色var(--color-zc-primary-500)
--zc-float-button-hover-border-color悬停边框色var(--color-zc-primary-300)
--zc-float-button-active-bg-color按下背景色var(--color-zc-fill-light)
--zc-float-button-box-shadow默认阴影var(--shadow-zc-md)
--zc-float-button-hover-box-shadow悬停阴影var(--shadow-zc-lg)
--zc-float-button-border-radius圆角(圆形模式)var(--radius-zc-circle)
--zc-float-button-border-radius-square圆角(方形模式)var(--radius-zc-base)
--zc-float-button-size默认尺寸48px
--zc-float-button-size-small小尺寸36px
--zc-float-button-size-large大尺寸56px
--zc-float-button-font-size图标大小20px

暗色模式

组件内置了暗色模式适配,当文档包含 .zc-dark 类或 [data-theme="dark"] 属性时,会自动切换配色。

html
<!-- 启用暗色模式 -->
<html class="zc-dark">
  <ZcFloatButton icon="🌙" type="primary" />
</html>

基于 MIT 许可发布