---
layout : 'default'
css : 'side'
title : 'Sidebar'
type : 'UI Module'
---
Any content can be used as a sidebar by adding the class ui sidebar
and initializing the menu in javascript.
Fixed position content may have issues changing it's position when a sidebar appears. There are two solutions
- Specify your fixed content without using the css left property
- Apply styles on the fixed element to adjust its position when the sidebar appears. You can do this by descending from the body tag which receives the class
pushed
when the view is moved.
$('.ui.sidebar')
.sidebar()
;
A sidebar can be shown, hidden, or toggled. In the following examples sidebar is used in conjunction with ui menu to display a vertical menu as a sidebar.
$('.demo.sidebar')
.sidebar('toggle')
;
For convenience calling attach events will allow you to bind events. By default this will toggle the sidebar in and out of view on click
$('.demo.sidebar')
.sidebar('attach events', '.toggle.button')
;
$('.toggle.button')
.removeClass('disabled')
;
Trigger Sidebar
You can also however specify what action should occur when the element is clicked
$('.demo.sidebar')
.sidebar('attach events', '.open.button', 'open')
;
$('.open.button')
.removeClass('disabled')
;
Open Sidebar
A sidebar can appear floating above content
$('.demo.sidebar')
.addClass('floating')
.sidebar('toggle')
;
A sidebar can appear on any side of content
$('.direction.button')
.on('click', function() {
$('.sidebar')
.filter('.' + $(this).data('direction') )
.sidebar('toggle')
;
})
;
$('.direction.button')
.removeClass('disabled')
;
A sidebar can overlay page content instead of pushing it to the side
$('.demo.sidebar')
.sidebar('setting', 'overlay', true)
.sidebar('toggle')
.sidebar('setting', 'overlay', false)
;