This is a slide out menu. You can add a dropdown to your sidebar by using our collapsible component. If you want to see a demo, our sidebar will use this on smaller screens. To use this in conjunction with a fullscreen navigation, you have to use two copies of the same UL.
To add a blur effect to the overlay, just add blur-overlay
to the sidenav
element. Or use blur-bg
instead if you just want to
blur the sidenav or blur-bg acrylic
if you want the acrylic
effect.
Please note that the sidenav HTML should not be contained within the navbar HTML.
Side nav demo Blurred Background Blurred Background, Acrylic Blurred Overlay
<nav> <!-- navbar content here --> </nav>
<ul id="slide-out" class="sidenav">
<li><div class="user-view">
<div class="background">
<img src="images/office.jpg">
</div>
<a href="#user"><img class="circle" src="images/yuna.jpg"></a>
<a href="#name"><span class="white-text name">John Doe</span></a>
<a href="#email"><span class="white-text email">jdoe@example.com</span></a>
</div></li>
<li><a href="#!"><i class="material-icons">cloud</i>First Link With Icon</a></li>
<li><a href="#!">Second Link</a></li>
<li><div class="divider"></div></li>
<li><a class="subheader">Subheader</a></li>
<li><a class="waves-effect" href="#!">Third Link With Waves</a></li>
</ul>
<a href="#" data-target="slide-out" class="sidenav-trigger"><i class="material-icons">menu</i></a>
If you prefer the Material Design 3 verision, just add md3 to the sidenav element
like this class="sidenav md3"
.
- inboxInbox 26
- sendOutbox 100+
- favorite_borderFavorites
- delete_outlineTrash
- Labels
- radio_button_uncheckedLabel
- change_historyLabel
- check_box_outline_blankLabel
<nav> <!-- navbar content here --> </nav>
<ul id="slide-out" class="sidenav md3">
<li class="title">
<span>Mail</span>
</li>
<li class="active">
<a href="#!" class="waves-effect">
<i class="material-icons">inbox</i>
Inbox
<span class="badge">26</span>
</a>
</li>
<li>
<a href="#!" class="waves-effect">
<i class="material-icons">send</i>
Outbox
<span class="badge">100+</span>
</a>
</li>
<li><div class="divider"></div></li>
<li><a class="subheader">Labels</a></li>
<li><a href="#!" class="waves-effect"><i class="material-icons">radio_button_unchecked</i>Label</a></li>
</ul>
<a href="#" data-target="slide-out" class="sidenav-trigger"><i class="material-icons">menu</i></a>
Initialization
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.sidenav');
var instances = M.Sidenav.init(elems, {
// specify options here
});
});
// Initialize collapsible (uncomment the lines below if you use the dropdown variation)
// var collapsibleElem = document.querySelector('.collapsible');
// var collapsibleInstance = M.Collapsible.init(collapsibleElem, {
// // specify options here
// });
// Or with jQuery
$(document).ready(function(){
$('.sidenav').sidenav({
// specify options here
});
});
Options
Name | Type | Default | Description |
---|---|---|---|
edge | String | 'left' | Side of screen on which Sidenav appears. |
draggable | Boolean | true | Allow swipe gestures to open/close Sidenav. |
dragTargetWidth | String | '10px' | Width of the area where you can start dragging. |
inDuration | Number | 250 | Length in ms of enter transition. |
outDuration | Number | 200 | Length in ms of exit transition. |
onOpenStart | Function | null | Function called when sidenav starts entering. |
onOpenEnd | Function | null | Function called when sidenav finishes entering. |
onCloseStart | Function | null | Function called when sidenav starts exiting. |
onCloseEnd | Function | null | Function called when sidenav finishes exiting. |
preventScrolling | Boolean | true | Prevent page from scrolling while sidenav is open. |
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.Sidenav.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. $('.sidenav').sidenav('methodName'); $('.sidenav').sidenav('methodName', paramName); */
.open();
Opens Sidenav.
instance.open();
.close();
Closes Sidenav.
instance.close();
.destroy();
Destroy plugin instance and teardown
instance.destroy();
Properties
Name | Type | Description |
---|---|---|
el | Element | The DOM element the plugin was initialized with. |
options | Object | The options the instance was initialized with. |
isOpen | Boolean | Describes open/close state of Sidenav. |
isFixed | Boolean | Describes if sidenav is fixed. |
isDragged | Boolean | Describes if Sidenav is being dragged. |
Close Trigger
Add the class
.sidenav-close
to an element inside the sidenav and any click
event on that element will cause the sidenav to close. This is useful in Single Page Apps where the
page does not refresh on link clicks.
<ul id="slide-out" class="sidenav">
<li><a class="sidenav-close" href="#!">Clicking this will close Sidenav</a></li>
</ul>
<a href="#" data-target="slide-out" class="sidenav-trigger"><i class="material-icons">menu</i></a>
Variations
Here are some useful variations and additional elements you can add to your sidebar.
Dropdown HTML Structure
Add collapsible menus to your sidebar.
<ul id="slide-out" class="sidenav">
<li><a href="#!">First Sidebar Link</a></li>
<li><a href="#!">Second Sidebar Link</a></li>
<li class="no-padding">
<ul class="collapsible collapsible-accordion">
<li>
<a class="collapsible-header">Dropdown<i class="material-icons">arrow_drop_down</i></a>
<div class="collapsible-body">
<ul>
<li><a href="#!">First</a></li>
<li><a href="#!">Second</a></li>
<li><a href="#!">Third</a></li>
<li><a href="#!">Fourth</a></li>
</ul>
</div>
</li>
</ul>
</li>
</ul>
<ul class="right hide-on-med-and-down">
<li><a href="#!">First Sidebar Link</a></li>
<li><a href="#!">Second Sidebar Link</a></li>
<li><a class="dropdown-trigger" href="#!" data-target="dropdown1">Dropdown<i class="material-icons right">arrow_drop_down</i></a></li>
<ul id='dropdown1' class='dropdown-content'>
<li><a href="#!">First</a></li>
<li><a href="#!">Second</a></li>
<li><a href="#!">Third</a></li>
<li><a href="#!">Fourth</a></li>
</ul>
</ul>
<a href="#" data-target="slide-out" class="sidenav-trigger"><i class="material-icons">menu</i></a>
Fullscreen HTML Structure
If you want the menu to be accessible on all screensizes you just have to add a simple helper class
show-on-large
to the
.sidenav-trigger
.
<ul id="slide-out" class="sidenav">
<li><a href="#!">First Sidebar Link</a></li>
<li><a href="#!">Second Sidebar Link</a></li>
</ul>
<a href="#" data-target="slide-out" class="sidenav-trigger show-on-large"><i class="material-icons">menu</i></a>
Fixed HTML Structure
Add the class
sidenav-fixed
to have the sidenav be fixed and open on large
screens and hides to the regular functionality on smaller screens. Our sidenav on the left is an
example of this.
<ul id="slide-out" class="sidenav sidenav-fixed">
<li><a href="#!">First Sidebar Link</a></li>
<li><a href="#!">Second Sidebar Link</a></li>
</ul>
<a href="#" data-target="slide-out" class="sidenav-trigger"><i class="material-icons">menu</i></a>
If you are planning on using this you will have to offset your content by the width of the side menu.
Also add the .sidenav-fixed
class on where the offset content
will be, which in our case is in header
or nav, main and footer.
<!-- If you use header to contain the nav -->
<header class="sidenav-fixed">
<nav>
<!-- Nav Contents -->
</nav>
</header>
<!-- or -->
<!-- If you only use the nav, without the header container -->
<nav class="sidenav-fixed">
<!-- Nav Contents -->
</nav>
<!-- This will be your page contents -->
<main class="sidenav-fixed">
<!-- Page Contents -->
</main>
<!-- And lastly, your footer -->
<footer class="sidenav-fixed">
<!-- Footer Contents -->
</footer>
<!-- If you will be using FAB to toolbar, please also use this -->
<!-- Toolbar FAB -->
<div class="fixed-action-btn toolbar sidenav-fixed">
<a class="btn-floating large">
<i class="material-icons">mode_edit</i>
</a>
<ul>
<li class="waves-effect"><a href="#!"><i class="material-icons">insert_chart</i></a></li>
<li class="waves-effect"><a href="#!"><i class="material-icons">format_quote</i></a></li>
<li class="waves-effect"><a href="#!"><i class="material-icons">publish</i></a></li>
<li class="waves-effect"><a href="#!"><i class="material-icons">attach_file</i></a></li>
</ul>
</div>