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];

绑定位置

通过 offset 属性绑定当前位置,[x, y] 分别为 x轴y轴 的偏移量。

html
<vd-fab v-model:offset="offset" :gap="gap" />
ts
const gap = [44, 16, 16, 16];
const offset = ref<number[]>([]);

初始距视图位置

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

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

操作按钮

默认插槽可自定义操作按钮,通过 v-model 控制是否展示操作栏,通过 direction 属性配置操作栏弹出方向,当一个方向弹出空间不足时,会自动弹出到另一方向。

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%;
}

自定义按钮

通过 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-
offset当前位置number[]-
right初始距视图右边缘距离string | number-
bottom初始距视图下边缘距离string | number-
axis可移动方向FabAxis'xy'
gap浮动操作按钮与视窗的最小间距FabGap[44, 16, 16, 16]
gap-navbar顶部间距是否自动添加导航栏高度booleantrue
gap-tabbar底部间距是否自动添加标签栏高度booleantrue
adsorb自动边缘吸附FabAdsorb-
direction操作栏弹出方向FabDirection'top'
icon按钮图标IconsName'add'
moveable是否允许移动booleantrue
lazy-render是否懒渲染booleantrue
z-index层级number2001+

代替原始 Props

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

Events

事件名说明回调参数
click点击时触发MouseEvent
open操作栏打开时触发-
opened操作栏打开动画结束时触发-
close操作栏关闭时触发-
closed操作栏关闭动画结束时触发-

Slots

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

Expose

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

赣ICP备2025061025号-1