Sidenav
A jQuery plugin that creates a slideout navigation on the right or left, for the sidebar css component see Sidebar.
Syntax with Options:
<head>
<script src="side-navigation.js"></script>
</head>
<body>
<div class="sidenav-container" id="mySidenavContainerId">
<a class="btn btn-default sidenav-toggler" href="#mySidenavContainerId">
<span aria-hidden="true" class="glyphicon glyphicon-align-justify"></span> Toggle
</a>
<div class="sidenav-menu-slider">
<div class="sidenav-menu">
... Your Side Nav Content ...
</div>
</div>
<div class="sidenav-content">
... Your Main Content ...
</div>
</div>
<script>
$('.sidenav-toggler').sideNavigation({
breakpoint: 768, // The window width that defines the desktop size. Default: 768.
container: null, // The class or ID of the container. Default: null.
content: '.sidenav-content', // The class or ID of the content. Default: '.sidenav-content'.
equalHeight: true, // The height of content and navigation should be equal.
gutter: '15px', // The space between the sidenav-slider and the sidenav-content. Default: 15px.
loadingIndicatorTPL: '<div class="loading-animation loading-animation-md"></div>', // Loading indicator template
navigation: '.sidenav-menu-slider', // The class or ID of the slider. Default: '.sidenav-menu-slider'.
position: 'left', // The position of the sidenav-slider. Possible values: left, right. Default: 'left'.
type: 'relative', // The type of sidenav in desktop. Possible values: relative, fixed, fixed-push. Default: 'relative'.
typeMobile: 'relative', // The type of sidenav in mobile. Possible values: relative, fixed, fixed-push. Default: 'relative'.
url: null, // The URL or $.ajax config object to fetch the content to inject into .sidebar-body. Default: null.
useDelegate: true, // The type of reference to use on the toggler event handler. Value false, directly binds click to the toggler.
width: '225px' // The width of the side navigation. Default: '225px'.
});
</script>
</body>
To create a sidenav relative to other elements inside your page, you must follow the markup structure shown above and pass the sidenav-container element to the plugin with the
href
attribute or thedata-target
attribute on the toggler. Thecontainer
option also allows you to pass the container via javascript ifhref
ordata-target
can't be used. The options above are optional.
<button class="btn btn-default sidenav-toggler" data-target="#mySidenavContainerId">
Sidenav Toggler
</button>
<div class="sidenav-container" id="mySidenavContainerId">
<div class="sidenav-menu-slider">
<div class="sidenav-menu">
<div class="col-md-12">... Your Side Nav Content ...</div>
</div>
</div>
<div class="sidenav-content">
<div class="col-md-12">... Your Main Content ...</div>
</div>
</div>
<script>
$('.sidenav-toggler').sideNavigation();
</script>
<button class="btn btn-default sidenav-toggler1">
Sidenav Toggler 1
</button>
<div class="sidenav-container" id="mySidenavContainerId1">
<div class="sidenav-menu-slider">
<div class="sidenav-menu">
<div class="col-md-12">... Your Side Nav Content ...</div>
</div>
</div>
<div class="sidenav-content">
<div class="col-md-12">... Your Main Content ...</div>
</div>
</div>
<script>
$('.sidenav-toggler1').sideNavigation({
container: '#mySidenavContainerId1',
position: 'right'
});
</script>
Side Navigation Data API
The Side Navigation data api was added for situations where there is limited control over the markup structure. The only markup needed is a toggler and a panel to hide and show. These items can be included anywhere on the page.
The minimum amount of attributes required is
data-toggle="sidenav"
andhref="#target"
ordata-target="#target"
. This will open and close a fixed position sidenav provided the markup below. The width of thesidenav-slider
,sidenav-menu
, and position of the sidenav must be set through css. When usingfixed-push
, padding must also be set via css on open to push the content over.
The data api allows for fixed-push style sidenavs with the attributes
data-content
,data-type
, anddata-type-mobile
.Data-content
is the id of the content to be pushed over when the nav is open.Data-type
anddata-type-mobile
give the option to specify the style of sidenav in desktop and mobile, respectively. The values can befixed
orfixed-push
and defaults to fixed.The open class name can be customized through the attribute
data-open-class
and will be added to toggler and content on open.
<head>
<script src="side-navigation.js"></script>
</head>
<div id="#wrapper">
<a class="btn btn-default" data-content="body" data-toggle="sidenav" data-type="fixed-push" href="#simpleSidenav2">Simple Sidenav 2 Toggler</a>
<div class="closed sidenav-fixed sidenav-menu-slider" id="simpleSidenav2">
<div class="sidebar sidebar-default sidenav-menu">
...
</div>
</div>
</div>
Lazy Loading Side Navigation Content
You can load content into the sidebar of the Side Navigation in one of two ways. At the very minimum, the only two things you need are a URL and that the sidebar has a child element with the
sidebar-body
class. Data fetched from the URL will be appended to thesidebar-body
element.
Using the Data API
Use attribute
data-url
on the toggle to load content into.sidenav-body
when the side navigation is opened.
Using the Options API
When configuring your sidenav, you can specify the url using either a string or a configuration object that will be passed to $.ajax
(though make sure the config object contains the url property).
<div class="sidenav-container">
<a class="btn btn-default sidenav-toggler" href="">
<span aria-hidden="true" class="glyphicon glyphicon-align-justify"></span> Toggle
</a>
<div class="sidenav-menu-slider">
<div class="sidenav-menu">
<div class="sidebar-body">
Dynamic Content will be appended here...
</div>
</div>
</div>
<div class="sidenav-content">
<div class="col-md-12">... Your Main Content ...</div>
</div>
</div>
<script>
$('.sidenav-toggler').sideNavigation({
...
// url can be either a string
url: '/foo.html',
// or it can be an ajax config object
url: {
url: '/foo.html',
type: 'POST',
success: function(response) {
// runs before the content is appended
},
// ...etc...
},
...
});
</script>
Lazy Loading Events and State
When using the
url
ordata-url
options, the plugin will fire an event when the content is loadedurlLoaded.lexicon.sidenav
.Also, while the content is being loaded, an element
.sidebar-loading
containing a loading animation will be added to the.sidebar-body
element. The.sidebar-loading
element will be removed when the content is done loading.The loading animation defaults to dotted spinner but can be customized through
loadingIndicatorTPL
in the options API ordata-loading-indicator-tpl
in the data API.If using the options API, the class will be added to the
.sidenav-menu
element.