menuMDUIDocs
color_lens
The new mdui 2 based on Material Design 3 and Web Components is now available. Check out the mdui 2 documentation.

Headroom

The Headroom plugin responds to page scrolling. For example, the app bar disappears when scrolling down and reappears when scrolling up.

The features for auto-hiding the app bar and auto-hiding the bottom navigation bar introduced earlier are implemented using this plugin.

Usage

  1. Calling via custom attributes (requires mdui.mutation() for initialization if the component is dynamically generated)
  2. Call via JavaScript

Usage

Call via Attributes

No JavaScript code is required using this method. Just add the mdui-headroom="options" attribute to the element to activate the plugin.

If the component is dynamically generated, mdui.mutation() needs to be called for initialization.

<div mdui-headroom style="position: fixed; top: 0; left: 0; right: 0;"></div>
demo

Call via JavaScript

Instantiate the plugin:

// selector is a CSS selector or a DOM element
// options are the parameters for the plugin, see the parameter list below
var inst = new mdui.Headroom(selector, options);
demo

Param

Param NameTypeDefaultDescription
toleranceint | Object5

Distance scrolled before triggering element hiding.

If the parameter value is a number, it means the trigger distance for scrolling up and down is the same.

It can also be an object specifying trigger distances for scrolling up and down separately. For example, { down: 10, up: 5 }.

offsetint0Distance from the top of the page before starting to hide the element while scrolling.
initialClassstringmdui-headroomCSS class added to the element after plugin initialization.
pinnedClassstringmdui-headroom-pinned-topCSS class added when the element is pinned.
unpinnedClassstringmdui-headroom-unpinned-topCSS class added when pinning is cancelled.

Method

Method NameDescription
pin()Makes the element pinned.
unpin()Makes the element hidden.
enable()Enables the headroom plugin.
disable()Disables the headroom plugin.
getState()Gets the current state of the element. There are four states (pinning, pinned, unpinning, unpinned).

Event

Event NameDescriptionParams
pin.mdui.headroomTriggered when starting to pin.event._detail.inst: Instance
pinned.mdui.headroomTriggered when pinning is finished.
unpin.mdui.headroomTriggered when starting to hide.
unpinned.mdui.headroomTriggered after hiding.