npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tanzhenxing/zx-fab

v1.0.3

Published

悬浮按钮

Readme

ZX-FAB 悬浮按钮组件

一个功能丰富、高度可定制的悬浮按钮组件,支持多种位置、方向和动画效果。

功能特点

  • 支持四个角落定位(左上、右上、左下、右下)
  • 支持水平和垂直方向展开
  • 多种动画效果(缩放、淡入淡出、滑动)
  • 高度可定制的样式
  • 可自定义按钮大小、图标和颜色

基本用法

<template>
  <zx-fab 
    :content="fabItems" 
    @trigger="handleTrigger" 
    @fabClick="handleFabClick"
  />
</template>

<script setup>
import { ref } from 'vue';

const fabItems = ref([
  {
    icon: 'star',
    text: '收藏',
    active: false
  },
  {
    icon: 'share',
    text: '分享',
    active: false
  },
  {
    icon: 'heart',
    text: '喜欢',
    active: false,
    selectedIcon: 'heart-fill'
  }
]);

const handleTrigger = ({ index, item }) => {
  console.log('点击了菜单项', index, item);
  // 可以在这里处理菜单项的激活状态
  fabItems.value[index].active = !fabItems.value[index].active;
};

const handleFabClick = () => {
  console.log('点击了主按钮');
};
</script>

属性说明

| 属性名 | 类型 | 默认值 | 说明 | |---------------------|------------------|------------|-------------------------------------------| | pattern | Object | {} | 样式模式对象,包含颜色等样式配置 | | horizontal | String | 'left' | 水平位置,可选值: 'left', 'right' | | vertical | String | 'bottom' | 垂直位置,可选值: 'top', 'bottom' | | direction | String | 'horizontal' | 展开方向,可选值: 'horizontal', 'vertical' | | content | Array | [] | 菜单项数组 | | show | Boolean | false | 初始是否展开菜单 | | popMenu | Boolean | true | 是否显示弹出菜单 | | mainButtonSize | Number/String | 55 | 主按钮尺寸 | | itemButtonSize | Number/String | 45 | 菜单项按钮高度 | | shadow | Boolean | true | 是否显示阴影 | | zIndex | Number | 10 | 组件z-index值 | | animationType | String | 'scale' | 动画类型,可选值: 'scale', 'fade', 'slide' | | animationDuration | Number | 300 | 动画持续时间(毫秒) | | mainIcon | String | 'plus' | 主按钮图标 | | closeOnClickOutside | Boolean | true | 点击外部是否关闭菜单 | | margin | Number/String | 15 | 边距 | | bottom | Number/String | 30 | 底部距离 | | borderRadius | Number/String | 45 | 圆角大小 |

pattern 对象属性

| 属性名 | 类型 | 默认值 | 说明 | |----------------|---------|-----------|-------------------------| | color | String | '#3c3e49' | 菜单项文字和图标颜色 | | selectedColor | String | '#007AFF' | 菜单项选中时文字和图标颜色 | | backgroundColor| String | '#fff' | 菜单背景色 | | buttonColor | String | '#007AFF' | 主按钮背景色 | | iconColor | String | '#fff' | 主按钮图标颜色 |

content 数组项属性

| 属性名 | 类型 | 必填 | 说明 | |-------------|---------|------|----------------------------------| | icon | String | 是 | 菜单项图标名称 | | selectedIcon| String | 否 | 菜单项选中时图标名称 | | text | String | 否 | 菜单项文字 | | active | Boolean | 否 | 菜单项是否激活 | | iconSize | String | 否 | 菜单项图标大小,默认为'55rpx' | | autoClose | Boolean | 否 | 点击菜单项后是否自动关闭,默认true |

事件

| 事件名 | 说明 | 回调参数 | |-----------|-----------------------------------|--------------------------------------| | fabClick | 点击主按钮时触发 | - | | trigger | 点击菜单项时触发 | {index: 索引, item: 菜单项} | | open | 菜单打开时触发 | - | | close | 菜单关闭时触发 | - |

方法

通过ref可以获取组件实例并调用以下方法:

| 方法名 | 说明 | 参数 | |---------|-----------|------| | open | 打开菜单 | - | | close | 关闭菜单 | - |

示例

不同位置

<!-- 左下角 (默认) -->
<zx-fab :content="items" horizontal="left" vertical="bottom" />

<!-- 右下角 -->
<zx-fab :content="items" horizontal="right" vertical="bottom" />

<!-- 左上角 -->
<zx-fab :content="items" horizontal="left" vertical="top" />

<!-- 右上角 -->
<zx-fab :content="items" horizontal="right" vertical="top" />

不同方向

<!-- 水平方向展开 (默认) -->
<zx-fab :content="items" direction="horizontal" />

<!-- 垂直方向展开 -->
<zx-fab :content="items" direction="vertical" />

自定义样式

<zx-fab 
  :content="items"
  :pattern="{
    color: '#333',
    selectedColor: '#ff6700',
    backgroundColor: '#f5f5f5',
    buttonColor: '#ff6700',
    iconColor: '#fff'
  }"
  :mainButtonSize="60"
  :itemButtonSize="50"
  :shadow="true"
  :borderRadius="30"
/>

不同动画效果

<!-- 缩放动画 (默认) -->
<zx-fab :content="items" animationType="scale" />

<!-- 淡入淡出动画 -->
<zx-fab :content="items" animationType="fade" />

<!-- 滑动动画 -->
<zx-fab :content="items" animationType="slide" />

自定义图标

<zx-fab :content="items" mainIcon="menu" />

禁用外部点击关闭

<zx-fab :content="items" :closeOnClickOutside="false" />

程序控制打开关闭

<template>
  <view>
    <button @click="openMenu">打开菜单</button>
    <button @click="closeMenu">关闭菜单</button>
    <zx-fab ref="fabRef" :content="items" />
  </view>
</template>

<script setup>
import { ref } from 'vue';

const fabRef = ref(null);

const openMenu = () => {
  fabRef.value.open();
};

const closeMenu = () => {
  fabRef.value.close();
};
</script>