Back to Materialize

Floating Action Button Content

jade/page-contents/floating-action-button-content.html

1.0.03.7 KB
Original Source

If you want a fixed floating action button, you can add multiple actions that will appear on hover. Our demo is in the bottom righthand corner of the page.

<div class="fixed-action-btn">
  <a class="btn-floating btn-large red">
    <i class="large material-icons">mode_edit</i>
  </a>
  <ul>
    <li><a class="btn-floating red"><i class="material-icons">insert_chart</i></a></li>
    <li><a class="btn-floating yellow darken-1"><i class="material-icons">format_quote</i></a></li>
    <li><a class="btn-floating green"><i class="material-icons">publish</i></a></li>
    <li><a class="btn-floating blue"><i class="material-icons">attach_file</i></a></li>
  </ul>
</div>

Initialization document.addEventListener('DOMContentLoaded', function() { var elems = document.querySelectorAll('.fixed-action-btn'); var instances = M.FloatingActionButton.init(elems, options); }); // Or with jQuery $(document).ready(function(){ $('.fixed-action-btn').floatingActionButton(); });

Options

NameTypeDefaultDescription
directionString'top'Direction FAB menu opens. Can be 'top', 'right', 'buttom', 'left'
hoverEnabledBooleantrueIf true, FAB menu will open on hover instead of click
toolbarEnabledBooleanfalseEnable transit the FAB into a toolbar on click
Methods

Because jQuery is no longer a dependency, all the methods are called on the plugin instance. You can get the plugin instance like this:

var instance = M.FloatingActionButton.getInstance(elem);

/* jQuery Method Calls
You can still use the old jQuery plugin method calls.
But you won't be able to access instance properties.

$('.fixed-action-btn').floatingActionButton('methodName');
$('.fixed-action-btn').floatingActionButton('methodName', paramName);
*/
.open();

Opens FAB.

instance.open();
.close();

Closes FAB.

instance.close();
.destroy();

Destroy plugin instance and teardown

instance.destroy();

Properties

NameTypeDescription
elElementThe DOM element the plugin was initialized with.
optionsObjectThe options the instance was initialized with.
isOpenBooleanDescribes open/close state of the FAB.

Horizontal FAB

Creating a horizontal FAB is easy! Just set the direction option.

mode_edit

  • insert_chart
  • format_quote
  • publish
  • attach_file
document.addEventListener('DOMContentLoaded', function() {
    var elems = document.querySelectorAll('.fixed-action-btn');
    var instances = M.FloatingActionButton.init(elems, {
      direction: 'left'
    });
  });

mode_edit

  • insert_chart
  • format_quote
  • publish
  • attach_file

Click-only FAB

If you want to disable the hover behaviour, and instead toggle the FAB menu when the user clicks on the large button (works great on mobile!), just add the click-to-toggle class to the FAB.

menu

  • insert_chart
  • format_quote
  • publish
  • attach_file
document.addEventListener('DOMContentLoaded', function() {
    var elems = document.querySelectorAll('.fixed-action-btn');
    var instances = M.FloatingActionButton.init(elems, {
      direction: 'left',
      hoverEnabled: false
    });
  });

FAB to Toolbar

Instead of displaying individual button options, you can transition your FAB into a toolbar on click. Just add the toolbar class to the FAB.

document.addEventListener('DOMContentLoaded', function() {
    var elems = document.querySelectorAll('.fixed-action-btn');
    var instances = M.FloatingActionButton.init(elems, {
      toolbarEnabled: true
    });
  });

  // Or with jQuery

  $('.fixed-action-btn').floatingActionButton({
    toolbarEnabled: true
  });