Go to homepage

Projects /

Floating Action Button

A floating button representing the primary page action.

View Demo

How to

The Floating Action Button component is used to display a fixed-positioned button that triggers the main page action.

The tooltip element is fully customizable: you can use it to include, for example, a navigation. The component will auto-change the size of the tooltip: it will morph from the size of the button to the size determined by its content. The final tooltip width is set updating the --fab-popover-width variable. 

Button Position #

The FAB component can be placed in one of the 4 corners adding one of the following class variations:

  • .fab--bottom-right
  • .fab--bottom-left
  • .fab--top-right
  • .fab--top-left

The vertical gap (distance between the button and the top/bottom of the viewport) is determined by the --fab-gap-y variable; the distance from the left/right of the viewport depends on the max width of the .fab > div element: 

<div class="fab fab--bottom-right js-fab"> <!-- 👈 -->
  <div> <!-- 👈 max-width of this element determines the distance from the left/right of the viewport -->
    <button class="fab__btn js-fab__btn" aria-label="Toggle popover">
      <!-- ... -->
    </button>
  </div>
</div>

Button Icons #

When the button is clicked, it triggers the icon transition. To change the icons, replace the two SVG .fab__icon elements (you can use inline SVG, SVG symbols, or icon fonts).

<button class="fab__btn js-fab__btn">
  <span class="fab__icon-wrapper">
    <svg class="fab__icon" viewBox="0 0 24 24">
      <!-- ... -->
    </svg>
  </span>

  <span class="fab__icon-wrapper">
    <svg class="fab__icon" viewBox="0 0 24 24">
      <!-- ... -->
    </svg>
  </span>
</button>

Visibility Offset #

Optionally, you can hide the FAB and show it only if a specific condition is met:

  • show the FAB when a specific element leaves the viewport: add the data-target-in attribute and set it equal to a unique selector of the trigger element;
  • show the FAB after the window has scrolled of a specific amount of pixels: add the data-offset-in attribute and set it equal to the amount in pixels. This can be combined with the data-target-in attribute;
  • hide the FAB when a specific element enters the viewport: add the data-target-out attribute and set it equal to a unique selector of the trigger element;
  • hide the FAB after the window has scrolled of a specific amount of pixels: add the data-offset-out attribute and set it equal to the amount in pixels. This can be combined with the data-target-out attribute.
<div class="fab fab--bottom-right js-fab" data-offset-in="200">
  <!-- ... -->
</div>

Categories

Bug report & feedback

Component Github page ↗

Project duplicated

Project created

Globals imported

There was an error while trying to export your project. Please try again or contact us.