The navigation drawer in MDUI (hereafter referred to as drawer) can slide out from the left or right side of the page, and a page can have multiple drawers.
The performance of the drawer bar on mobile phones, tablets, and desktop devices is somewhat different. You can observe the changes of the drawer bar on the left side of this page by changing the width of the browser:
.mdui-drawer-full-height
You can make the height of the drawer bar 100%. At this time, the drawer bar may cover the top of the app bar. You can add a class to the app bar. .mdui-appbar-inset
Make the app bar not covered by the drawer bar..mdui-color-[color]
You can set the background color of the drawer bar and add shadows..mdui-drawer-open
The drawer bar can be displayed by default on all devices; add class .mdui-drawer-close
The drawer bar can be hidden by default on all devices.overlay
The parameters are true
, The mask layer can be displayed when the drawer is opened. If it is set to display the mask layer, then you should add .mdui-drawer-close
The class makes the drawer bar hidden by default.mdui.mutation()
Initialize)<!-- mdui-drawer-body-left Add padding-left to the class body, as long as there is a drawer bar opened by default on the left, add this class. -->
<!-- mdui-drawer-body-right Add padding-right to the class body, as long as there is a drawer on the right side that is opened by default, add this class. -->
<body class="mdui-drawer-body-left mdui-drawer-body-right">
<!-- The default drawer bar is on the left -->
<div class="mdui-drawer">
... drawer content ...
</div>
<!-- If you want to make the drawer bar on the right, you need to add a class mdui-drawer-right -->
<div class="mdui-drawer mdui-drawer-right">
... drawer content ...
</div>
</body>
There is no need to write JavaScript code to use this method. Just in a controlling element(For example: button)Add on mdui-drawer="options"
Attributes. When calling through custom attributes, you need to add an additionaltarget
The parameter is used to specify the drawer to be controlled, and its value is the CSS selector of the drawer to be controlled.
<body class="mdui-drawer-body-right">
<button class="mdui-btn" mdui-drawer="{target: '#left-drawer'}">open left drawer</button>
<div class="mdui-drawer" id="left-drawer">
... left drawer content ...
<button class="mdui-btn" mdui-drawer-close>close</button>
</div>
</body>
Some attributes can be added to the elements in the drawer bar to bind events, and these attributes can also be used when using JavaScript invocation methods.
Attributes | Description |
---|---|
mdui-drawer-close |
Clicking on the element will trigger close.mdui.drawer Event and close the drawer. |
// selector is the CSS selector or DOM element of the drawer bar
// options are configuration parameters, see the parameter list below
var inst = new mdui.Drawer(selector, options);
parameter name | Types of | Defaults | description |
---|---|---|---|
overlay |
boolean |
false |
Whether to show the mask layer when the drawer is opened. This parameter is only valid for devices with medium screens and above, and the mask layer will always be displayed on ultra-small screens and small screen devices. |
swipe |
boolean |
false |
Whether to enable swipe gestures. |
Method name | description |
---|---|
open |
Show the drawer bar. |
close |
Hide the drawer bar. |
toggle |
Switch the display status of the drawer bar. |
getState |
Returns the state of the current drawer bar. Contains four states(opening 、opened 、closing 、closed )。 |
event | description | the goal | parameter |
---|---|---|---|
open.mdui.drawer |
The event will be triggered when the drawer bar starts to open the animation. | <div class="mdui-drawer"></div> |
event._detail.inst : Examples |
opened.mdui.drawer |
The event will be triggered when the drawer bar completes the opening animation. | ||
close.mdui.drawer |
The event will be triggered when the drawer bar starts to close the animation. | ||
closed.mdui.drawer |
The event will be triggered when the drawer bar finishes closing animation. |
Class name | effect |
---|---|
.mdui-drawer |
Define a drawer bar. |
.mdui-drawer-right |
On the drawer bar on the right side of the page. |
.mdui-drawer-full-height |
Make the drawer bar occupy 100% of the height. |
.mdui-drawer-open |
Make the drawer bar display by default. |
.mdui-drawer-close |
Make the drawer bar hidden by default. |
.mdui-drawer-body-left |
for body Add to padding-left |
.mdui-drawer-body-right |
for body Add to padding-right |
Theme color
Main color
Accent color