vue-floating-action-button

repository·master·Indexed 41 days ago

https://github.com/a62527776a/vue-floating-action-button

A lightweight, zero-dependency Vue 2.0 component for creating Floating Action Buttons (FAB) with support for Material Design and iconfont animations. It provides the <vue-fab> and <fab-item> components, allowing for customizable colors, expansion directions, and scroll-based auto-hide behaviors. Version 0.7.9.

Tokens
6.5K
Snippets
29
Records
34
Agent score
43%

What's inside vue-floating-action-button

  1. Configure icon types (Material Design vs iconfont)

    master

    The component supports two icon systems. You must ensure the corresponding CSS is loaded in your project.

    Material Design Icons

    1. Include the Material Icons stylesheet in your index.html: <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    2. Set iconType: 'MaterialDesign' in the Vue.use() configuration.
    3. Pass icon names (e.g., icon="add") to the components.

    Alibaba Iconfont

    1. Include your iconfont CSS as per Alibaba's instructions.
    2. Set iconType: 'iconfont' in the Vue.use() configuration.
    3. Pass icon class names (e.g., icon="icon-jia") to the components.
    <!-- Material Design Example -->
    <vue-fab mainBtnColor="#3599DB">
      <fab-item @clickItem="clickItem" :idx="0" title="add" icon="add" />
    </vue-fab>
    
    <!-- Iconfont Example -->
    <vue-fab icon="icon-jia" fabItemAnimate="default" mainBtnColor="#16C2C2">
      <fab-item @clickItem="clickBABA" icon="icon-Rxing" :idx="0" title="iconfont.cn" />
    </vue-fab>
  2. Initialize VueFab in your Vue application

    master

    To use the component, import VueFab and register it using Vue.use(). You can optionally provide an iconType to specify whether you are using Material Design icons or iconfont.

    import Vue from 'vue'
    import VueFab from 'vue-float-action-button'
    import App from './App.vue'
    
    Vue.use(VueFab, {
      // iconType can be 'MaterialDesign' or 'iconfont'
      iconType: 'MaterialDesign'
    })
    
    new Vue({
      render: h => h(App)
    }).$mount('#app')
  3. Customize fab-item icons using slots

    master

    The fab-item component provides a slot that allows you to replace the default icon with custom content, such as an image.

    Important: When using a slot to provide a custom image or element, you must manually configure the element's width, height, and border-radius via inline styles to ensure it fits correctly within the floating action button item container.

    <vue-fab icon="add" size="normal" >
      <fab-item @clickItem="clickItem" :idx="1" icon="edit">
        <img 
          src="your-image-url.jpg" 
          style="width: 100%; height: 100%; border-radius: 50%" 
        />
      </fab-item>
    </vue-fab>
  4. Register vue-float-action-button in Vue

    master

    To use the component, register it using Vue.use(). You can optionally provide a configuration object to specify the icon type.

    Supported iconType values:

    • MaterialDesign (default behavior if using Material Icons)
    • iconfont (for Alibaba Iconfont)
    import Vue from 'vue'
    import VueFab from 'vue-float-action-button'
    
    Vue.use(VueFab, {
      // iconType can be 'MaterialDesign' or 'iconfont'
      iconType: 'MaterialDesign'
    })
  5. Configure iconfont support in VueFab

    master

    By default, vue-float-action-button uses the Material Design icon library. If your project uses Alibaba's iconfont, you can configure the plugin to support it using the iconType option during installation.

    Once configured, the component abstracts the difference between the two libraries, allowing you to simply pass the icon name to the icon prop.

    Vue.use(VueFab, {
      // Options can be 'iconfont' or 'MaterialDesign'
      iconType: 'iconfont'
    })
  6. Configure FabItem expansion animations

    master

    You can control the transition animation used when opening or closing the sub-menu of the FAB using the fabItemAnimate prop on the <vue-fab> component.

    Available modes:

    • 'default': Each item transitions individually.
    • 'alive': Uses a 'splitting' transition effect.
    <vue-fab 
      :fabItemAnimate="fabItemAnimate">
      <fab-item v-for="idx in 4" :idx="idx - 1" />
    </vue-fab>
    
    <script>
    export default {
      data () {
        return {
          fabItemAnimate: 'default' // Options: 'default' or 'alive'
        }
      }
    }
    </script>
  7. Configure scrolling auto-hide animations

    master

    You can control how the Floating Action Button (FAB) behaves when scrolling using the fabAutoHideAnimateModel prop on the <vue-fab> component. This determines the animation style used when the button automatically hides during scroll events.

    Available modes:

    • 'default': The button shrinks to hide.
    • 'alive': The button hides by moving downwards.
    <vue-fab 
      :fabAutoHideAnimateModel="fabAutoHideAnimateModel">
    </vue-fab>
    
    <script>
    export default {
      data () {
        return {
          fabAutoHideAnimateModel: 'default' // Options: 'default' or 'alive'
        }
      }
    }
    </script>
  8. Install the Vue Floating Action Button plugin

    master

    To use the library in your Vue application, install it and use the Vue.use() method. You can optionally provide a global configuration object to set a default iconType for all FAB components.

    import Vue from 'vue';
    import VueFab from 'vue-float-action-button';
    
    // Optional: Set a global default iconType
    Vue.use(VueFab, {
      iconType: 'your-default-icon-type'
    });
  9. Troubleshoot Safari click-to-close issues

    master

    In Safari, window, document, and body may not respond to click events, which can prevent the menu from closing when clicking on empty space.

    Solution: Ensure your html tag has a height of 100%. If it does not, apply the following CSS:

    html {
      min-height: 100%;
    }