Component for sliding UI where one page is overlayed over another page. The above page can be slided aside to reveal the page behind.
<ons-sliding-menu var="app.menu" main-page="page.html" menu-page="menu.html" max-slide-distance="200px" type="reveal" side="left">
</ons-sliding-menu>
<ons-template id="page.html">
<ons-page>
<p style="text-align: center">
<ons-button ng-click="app.menu.toggleMenu()">Toggle</ons-button>
</p>
</ons-page>
</ons-template>
<ons-template id="menu.html">
<ons-page>
<!-- menu page's contents -->
</ons-page>
</ons-template>
See the Pen Alert, confirm and prompt dialogs by Onsen & Monaca (@onsen) on CodePen.
| Name | Type Default Value |
Description |
|---|---|---|
| var | String | Variable name to refer this sliding menu. Optional |
| menu-page | String | The url of the menu page. Optional |
| main-page | String | The url of the main page. Optional |
| swipeable | Boolean | Whether to enable swipe interaction. Optional |
| swipe-target-width | String | The width of swipeable area calculated from the left (in pixels). Use this to enable swipe only when the finger touch on the screen edge. Optional |
| max-slide-distance | String | How far the menu page will slide open. Can specify both in px and %. eg. 90%, 200px Optional |
| direction | String | Specify which side of the screen the menu page is located on. Possible values are "left" and "right". Optional |
| type | String | Sliding menu animator. Possible values are reveal (default), push and overlay. Optional |
| ons-preopen | Expression | Allows you to specify custom behavior when the "preopen" event is fired. Optional |
| ons-preclose | Expression | Allows you to specify custom behavior when the "preclose" event is fired. Optional |
| ons-postopen | Expression | Allows you to specify custom behavior when the "postopen" event is fired. Optional |
| ons-postclose | Expression | Allows you to specify custom behavior when the "postclose" event is fired. Optional |
| ons-destroy | Expression | Allows you to specify custom behavior when the "destroy" event is fired. Optional |
| Signature | Description |
|---|---|
| setMainPage(pageUrl, [options]) | Show the page specified in pageUrl in the main contents pane. |
| setMenuPage(pageUrl, [options]) | Show the page specified in pageUrl in the side menu pane. |
| openMenu([options]) | Slide the above layer to reveal the layer behind. |
| closeMenu([options]) | Slide the above layer to hide the layer behind. |
| toggleMenu([options]) | Slide the above layer to reveal the layer behind if it is currently hidden, otherwise, hide the layer behind. |
| isMenuOpened() | Returns true if the menu page is open, otherwise false. |
| getDeviceBackButtonHandler() | Retrieve the back-button handler. |
| setSwipeable(swipeable) | Specify if the menu should be swipeable or not. |
| on(eventName, listener) | Add an event listener. |
| once(eventName, listener) | Add an event listener that's only triggered once. |
| off(eventName, [listener]) | Remove an event listener. If the listener is not specified all listeners for the event type will be removed. |
| Name | Description |
|---|---|
| preopen | Fired just before the sliding menu is opened. |
| postopen | Fired just after the sliding menu is opened. |
| preclose | Fired just before the sliding menu is closed. |
| postclose | Fired just after the sliding menu is closed. |
Show the page specified in pageUrl in the main contents pane.
| Name | Type | Description |
|---|---|---|
| pageUrl | String | Page URL. Can be either an HTML document or an <ons-template>. |
| options | Object | Parameter object. |
| options.closeMenu | Boolean | If true the menu will be closed. |
| options.callback | Function | Function that is executed after the page has been set. |
Show the page specified in pageUrl in the side menu pane.
| Name | Type | Description |
|---|---|---|
| pageUrl | String | Page URL. Can be either an HTML document or an <ons-template>. |
| options | Object | Parameter object. |
| options.closeMenu | Boolean | If true the menu will be closed after the menu page has been set. |
| options.callback | Function | This function will be executed after the menu page has been set. |
Slide the above layer to reveal the layer behind.
| Name | Type | Description |
|---|---|---|
| options | Object | Parameter object. |
| options.callback | Function | This function will be called after the menu has been opened. |
Slide the above layer to hide the layer behind.
| Name | Type | Description |
|---|---|---|
| options | Object | Parameter object. |
| options.callback | Function | This function will be called after the menu has been closed. |
Slide the above layer to reveal the layer behind if it is currently hidden, otherwise, hide the layer behind.
| Name | Type | Description |
|---|---|---|
| options | Object | Parameter object. |
| options.callback | Function | This function will be called after the menu has been opened or closed. |
Returns true if the menu page is open, otherwise false.
Returns: true if the menu is currently open.
Retrieve the back-button handler.
Returns: Device back button handler.
Specify if the menu should be swipeable or not.
| Name | Type | Description |
|---|---|---|
| swipeable | Boolean | If true the menu will be swipeable. |
Add an event listener.
| Name | Type | Description |
|---|---|---|
| eventName | String | Name of the event. |
| listener | Function | Function to execute when the event is triggered. |
Add an event listener that's only triggered once.
| Name | Type | Description |
|---|---|---|
| eventName | String | Name of the event. |
| listener | Function | Function to execute when the event is triggered. |
Remove an event listener. If the listener is not specified all listeners for the event type will be removed.
| Name | Type | Description |
|---|---|---|
| eventName | String | Name of the event. |
| listener | Function | Function to execute when the event is triggered. |
Fired just before the sliding menu is opened.
| Name | Type | Description |
|---|---|---|
| event | Object | Event object. |
| event.slidingMenu | Object | Sliding menu view object. |
Fired just after the sliding menu is opened.
| Name | Type | Description |
|---|---|---|
| event | Object | Event object. |
| event.slidingMenu | Object | Sliding menu view object. |
Fired just before the sliding menu is closed.
| Name | Type | Description |
|---|---|---|
| event | Object | Event object. |
| event.slidingMenu | Object | Sliding menu view object. |
Fired just after the sliding menu is closed.
| Name | Type | Description |
|---|---|---|
| event | Object | Event object. |
| event.slidingMenu | Object | Sliding menu view object. |
Get updates on Onsen UI, Monaca and hybrid app development. No more than 2-3 times a month.