Skip to content

Fab 悬浮按钮

介绍

悬浮动作按钮,可移动和边缘吸附,支持设置按钮动作组,在按钮按下时展示。

基础用法

通过 axis 属性配置可限制移动方向,通过 gap 属性配置浮动操作按钮与视窗的最小间距。

html
<vd-fab axis="xy" :gap="gap" />
ts
const gap = [44, 16, 16, 16];

边缘吸附

通过 adsorb 属性配置是否自动边缘吸附,移动后会吸附到视窗的指定轴边缘上。

html
<vd-fab :gap="gap" adsorb="x" />
ts
const gap = [44, 16, 16, 16];

初始距视图位置

通过 rightbottom 属性设置初始距视图位置。

html
<vd-fab :gap="gap" right="36" bottom="120" />
ts
const gap = [44, 16, 16, 16];

操作按钮

默认插槽可自定义操作按钮,通过 v-model 控制是否展示操作栏,通过 direction 属性配置操作栏弹出方向。线性模式下空间不足时优先翻到对侧(上↔下、左↔右),对侧仍不够再看相邻方向;圆形模式(含自定义 circle-arc):当前半径下完整基准可放则保持原跨度;空间不足时由 circle-avoid 控制(auto 先压角再缩半径,arc 只压角,radius 只缩半径,none 不避让)。圆形避让会按子项实测最大半宽半高内缩可用空间(未测到时用主按钮尺寸兜底)。

html
<vd-fab v-model="show" :gap="gap" direction="left">
  <vd-button type="primary" icon="like" />
  <vd-button type="success" icon="star" />
  <vd-button type="warning" icon="coin" />
</vd-fab>
ts
const show = ref(false);
const gap = [44, 16, 16, 16];
css
.vd-fab .vd-button {
  font-size: 18px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
}

圆形展开

通过 circle 开启圆形展开,配合 vd-fab-item 使用。direction 决定默认扇形(上 / 右 / 下 / 左半圆,如右为 [-90, 90]);避让:按子项半尺寸内缩 → 归一化 circle-arc → 空间足够则保持完整基准 → circle-avoid(默认 auto)时优先保持原始跨度旋转避让(如 [0,-45][-90,-45]),滑不动再在不超过原始跨度内裁角;角向已能放下则不缩半径,仍不够才缩半径。circle-avoid 可选 auto / arc / radius / nonecircle-radius 为期望半径(支持 CSS 尺寸,经 Offset 换算为实际 px),circle-arc 可覆盖起止角( 正右、逆时针为正)。循环时请传入 index

html
<vd-fab
  v-model="show"
  :gap="gap"
  direction="top"
  circle
  :circle-radius="75"
>
  <vd-fab-item
    v-for="(item, index) in actions"
    :key="index"
    :index="index"
  >
    <vd-button :type="item.type" :icon="item.icon" />
  </vd-fab-item>
</vd-fab>
ts
const show = ref(false);
const gap = [44, 16, 16, 16];
const actions = [
  { type: 'primary', icon: 'like' },
  { type: 'success', icon: 'star' },
  { type: 'warning', icon: 'coin' },
];

自定义按钮

通过 trigger 插槽可自定义触发按钮。

html
<vd-fab :gap="gap">
  <template #trigger>
    <view class="fab-trigger">
      <vd-icon name="coin" />
      <view class="txt">新增</view>
    </view>
  </template>
</vd-fab>
ts
const gap = [44, 16, 16, 16];
scss
.fab-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding-bottom: 4px;

  .vd-icon {
    margin-bottom: 6px;
    font-size: 18px;
  }

  .txt {
    font-size: 10px;
    line-height: 1;
  }
}

API

Props

参数说明类型默认值
v-model操作栏是否展示boolean-
right初始距视图右边缘距离string | number-
bottom初始距视图下边缘距离string | number-
axis可移动方向FabAxis'xy'
gap浮动操作按钮与视窗的最小间距FabGap[44, 16, 16, 16]
gap-navbar顶部间距是否自动添加导航栏高度booleantrue
gap-tabbar底部间距是否自动添加标签栏高度booleantrue
adsorb自动边缘吸附FabAdsorb-
direction操作栏弹出方向;circle 时同时决定默认扇形朝向FabDirection'top'
circle是否圆形展开booleanfalse
circle-radius圆形展开半径,支持 CSS 尺寸;仅 circle 时生效string | number75
circle-arc圆形展开扇形起止角,单位 deg;仅 circle 时生效,未传按 direction 推导FabCircleArc-
circle-avoid圆形展开避让方式;auto 先压角再缩半径,arc 只压角,radius 只缩半径,none 不避让FabCircleAvoid'auto'
icon按钮图标IconsName'add'
moveable是否允许移动booleantrue
lazy-render是否懒渲染booleantrue
z-index层级number2001+

代替原始 Props

参数说明类型默认值
custom-id根节点idstring-
custom-class根节点类名ClassValue-
custom-style根节点样式StyleValue-

Events

事件名说明回调参数
click点击时触发MouseEvent
update:model-value操作栏展示状态更新时触发boolean
open操作栏打开时触发-
opened操作栏打开动画结束时触发-
close操作栏关闭时触发-
closed操作栏关闭动画结束时触发-

Slots

名称说明
default操作栏内容
trigger操作按钮

FabItem Props

参数说明类型默认值
index索引,循环时设置该值防止顺序异常string | number-

代替原始 Props

参数说明类型默认值
custom-id根节点idstring-
custom-class根节点类名ClassValue-
custom-style根节点样式StyleValue-

FabItem Events

事件名说明回调参数
click点击时触发MouseEvent

FabItem Slots

名称说明
default操作项内容

Expose

方法名说明参数返回值
update手动触发位置计算-Promise<void>

类型定义

组件导出以下类型定义:

ts
import type {
  FabAxis,
  FabGap,
  FabAdsorb,
  FabDirection,
  FabCircleArc,
  FabCircleAvoid,
  FabExpose,
  FabInstance,
  FabItemInstance,
} from 'vital-design';

赣ICP备2025061025号-1