A floating action button (FAB) represents the primary action on a screen. It is a circular icon that appears to float above the interface and can trigger actions such as opening a speed-dial menu or showing or hiding content.
Add the class .mdui-fab to an element to make it a floating action button.
<button class="mdui-fab mdui-ripple">
<i class="mdui-icon material-icons">add</i>
</button>
<button class="mdui-fab mdui-color-theme-accent mdui-ripple">
<i class="mdui-icon material-icons">add</i></button
>Adding the class .mdui-fab-mini makes it a mini floating action button.
<button class="mdui-fab mdui-fab-mini mdui-ripple">
<i class="mdui-icon material-icons">add</i>
</button>
<button
class="mdui-fab mdui-fab-mini mdui-color-theme-accent mdui-ripple"
>
<i class="mdui-icon material-icons">add</i></button
>Adding the class .mdui-fab-hide to a floating action button will hide it with an animation; removing the class will show it with an animation.
<button
class="mdui-fab mdui-color-theme-accent mdui-ripple"
id="fab-animation"
>
<i class="mdui-icon material-icons">add</i>
</button>
<button class="mdui-btn" id="fab-animation-show">show</button>
<button class="mdui-btn" id="fab-animation-hide">hide</button>
<script>
var fab = document.getElementById('fab-animation');
document
.getElementById('fab-animation-show')
.addEventListener('click', function () {
fab.classList.remove('mdui-fab-hide');
});
document
.getElementById('fab-animation-hide')
.addEventListener('click', function () {
fab.classList.add('mdui-fab-hide');
});
</script>
Adding the class .mdui-fab-fixed will fix the button to the bottom right of the window.
<button class="mdui-fab mdui-fab-fixed mdui-ripple">
<i class="mdui-icon material-icons">add</i>
</button>RunThis button is always fixed to the bottom right of the window. Hovering over or clicking it opens a speed-dial menu upward.
<div class="mdui-fab-wrapper" id="exampleFab">
<button class="mdui-fab mdui-ripple mdui-color-theme-accent">
<!-- Icon shown by default -->
<i class="mdui-icon material-icons">add</i>
<!-- Smoothly switches to this icon when the speed dial starts to open; this element can be omitted if no icon switch is needed. -->
<i class="mdui-icon mdui-fab-opened material-icons">add</i>
</button>
<div class="mdui-fab-dial">
<button class="mdui-fab mdui-fab-mini mdui-ripple mdui-color-pink">
<i class="mdui-icon material-icons">backup</i>
</button>
<button class="mdui-fab mdui-fab-mini mdui-ripple mdui-color-red">
<i class="mdui-icon material-icons">bookmark</i>
</button>
<button class="mdui-fab mdui-fab-mini mdui-ripple mdui-color-orange">
<i class="mdui-icon material-icons">access_alarms</i>
</button>
<button class="mdui-fab mdui-fab-mini mdui-ripple mdui-color-blue">
<i class="mdui-icon material-icons">touch_app</i>
</button>
</div>
</div>This method does not require writing JavaScript code. Simply add mdui-fab="options" to the element containing .mdui-fab-wrapper to activate the plugin.
<div class="mdui-fab-wrapper" mdui-fab="{trigger: 'hover'}">
......
</div>Instantiate component:
// selector is a CSS selector, DOM element, or HTML string
// options are plugin parameters, see the parameter list below
var inst = new mdui.Fab(selector, options);| Param Name | Type | Default | Description |
|---|---|---|---|
trigger | string | hover | Trigger method.
|
| Method Name | Description |
|---|---|
open() | Open the speed dial menu. |
close() | Close the speed dial menu. |
toggle() | Toggle the open state of the speed dial menu. |
show() | Show the entire floating action button with an animation. |
hide() | Hide the entire floating action button with an animation. |
getState() | Returns the current open state of the speed dial menu. There are four states (opening, opened, closing, closed). |
| Event Name | Description | Target | Params |
|---|---|---|---|
open.mdui.fab | Triggered when the speed dial menu starts its opening animation. | <div class="mdui-fab-wrapper"></div> | event._detail.inst: Instance |
opened.mdui.fab | Triggered when the speed dial menu completes its opening animation. | ||
close.mdui.fab | Triggered when the speed dial menu starts its closing animation. | ||
closed.mdui.fab | Triggered when the speed dial menu completes its closing animation. |
| Class Name | Description |
|---|---|
.mdui-fab | Defines a floating action button. |
.mdui-fab-mini | Defines a mini floating action button. |
.mdui-fab-hide | Hides the floating action button with an animation. |
.mdui-fab-fixed | Fixes the floating action button to the bottom right. |
.mdui-fab-wrapper | The outer element for a floating action button with a speed dial menu. |
.mdui-fab-opened | The icon switched to after the floating action button with a speed dial menu opens its menu. |
.mdui-fab-dial | The outer element for the menu items of a floating action button with speed dial. |